X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/5178870c9c7f80d0c6f1b715d0131320d8f5bc90..90e389f6ec12e60a62c362296ffcf314feb5b03d:/stglibs/logger.lib/logger.h diff --git a/stglibs/logger.lib/logger.h b/stglibs/logger.lib/logger.h new file mode 100644 index 00000000..f8375b06 --- /dev/null +++ b/stglibs/logger.lib/logger.h @@ -0,0 +1,42 @@ +#ifndef STG_LOGGER_H +#define STG_LOGGER_H + +#include + +#include + +#include "stg/noncopyable.h" + +const char * LogDate(time_t t); +//----------------------------------------------------------------------------- +class STG_LOGGER; +STG_LOGGER & GetStgLogger(); +//----------------------------------------------------------------------------- +class STG_LOGGER_LOCKER : private NONCOPYABLE +{ +public: + STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; + ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; +private: + pthread_mutex_t * mutex; +}; +//----------------------------------------------------------------------------- +class STG_LOGGER +{ +friend STG_LOGGER & GetStgLogger(); + +public: + ~STG_LOGGER(); + void SetLogFileName(const std::string & fn); + void operator()(const char * fmt, ...); + +private: + STG_LOGGER(); + const char * LogDate(time_t t); + + std::string fileName; + pthread_mutex_t mutex; +}; +//----------------------------------------------------------------------------- + +#endif //STG_LOGGER_H