]> git.stg.codes - stg.git/blob - stglibs/logger.lib/include/stg/logger.h
TUT framework updated to svn version
[stg.git] / stglibs / logger.lib / include / stg / logger.h
1 #ifndef STG_LOGGER_H
2 #define STG_LOGGER_H
3
4 #include <pthread.h>
5
6 #include <string>
7
8 const char * LogDate(time_t t);
9 //-----------------------------------------------------------------------------
10 class STG_LOGGER;
11 STG_LOGGER & GetStgLogger();
12 //-----------------------------------------------------------------------------
13 class STG_LOGGER_LOCKER
14 {
15 public:
16     STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); };
17     ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); };
18
19 private:
20     STG_LOGGER_LOCKER(const STG_LOGGER_LOCKER & rvalue);
21     STG_LOGGER_LOCKER & operator=(const STG_LOGGER_LOCKER & rvalue);
22
23     pthread_mutex_t * mutex;
24 };
25 //-----------------------------------------------------------------------------
26 class STG_LOGGER
27 {
28 friend STG_LOGGER & GetStgLogger();
29
30 public:
31     ~STG_LOGGER();
32     void SetLogFileName(const std::string & fn);
33     void operator()(const char * fmt, ...);
34
35 private:
36     STG_LOGGER();
37     STG_LOGGER(const STG_LOGGER & rvalue);
38     STG_LOGGER & operator=(const STG_LOGGER & rvalue);
39
40     const char * LogDate(time_t t);
41
42     std::string fileName;
43     pthread_mutex_t mutex;
44 };
45 //-----------------------------------------------------------------------------
46
47 #endif //STG_LOGGER_H