X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/90e389f6ec12e60a62c362296ffcf314feb5b03d..793728a58d8f97daf7de1dde7a02a5c4a30e30d4:/stglibs/logger.lib/logger.cpp?ds=inline diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index 18c9de7e..14c09591 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -2,7 +2,7 @@ #include #include -#include "logger.h" +#include "stg/logger.h" #ifdef STG_TIME extern const volatile time_t stgTime; @@ -15,7 +15,8 @@ return logger; } //----------------------------------------------------------------------------- STG_LOGGER::STG_LOGGER() - : fileName() + : fileName(), + mutex() { pthread_mutex_init(&mutex, NULL); } @@ -31,7 +32,7 @@ STG_LOGGER_LOCKER lock(&mutex); fileName = fn; } //----------------------------------------------------------------------------- -void STG_LOGGER::operator()(const char * fmt, ...) +void STG_LOGGER::operator()(const char * fmt, ...) const { STG_LOGGER_LOCKER lock(&mutex); @@ -73,7 +74,7 @@ else } } //----------------------------------------------------------------------------- -const char * STG_LOGGER::LogDate(time_t t) +const char * STG_LOGGER::LogDate(time_t t) const { static char s[32]; if (t == 0) @@ -92,3 +93,34 @@ snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d", return s; } //----------------------------------------------------------------------------- +PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn) + : STG_LOGGER(), + pluginName(pn) +{ + SetLogFileName(logger.fileName); +} +//----------------------------------------------------------------------------- +PLUGIN_LOGGER::PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs) + : STG_LOGGER(), + pluginName(rhs.pluginName) +{ + SetLogFileName(fileName); +} +//----------------------------------------------------------------------------- +void PLUGIN_LOGGER::operator()(const char * fmt, ...) const +{ +char buff[2029]; + +va_list vl; +va_start(vl, fmt); +vsnprintf(buff, sizeof(buff), fmt, vl); +va_end(vl); + +STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff); +} +//----------------------------------------------------------------------------- +PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName) +{ +return PLUGIN_LOGGER(logger, pluginName); +} +//-----------------------------------------------------------------------------