1 #include "stg/logger.h"
 
   8 extern const volatile time_t stgTime;
 
  12 using STG::PluginLogger;
 
  14 //-----------------------------------------------------------------------------
 
  20 //-----------------------------------------------------------------------------
 
  21 void Logger::setFileName(const std::string& fn)
 
  23     std::lock_guard<std::mutex> lock(mutex);
 
  26 //-----------------------------------------------------------------------------
 
  27 void Logger::operator()(const char* fmt, ...) const
 
  29     std::lock_guard<std::mutex> lock(mutex);
 
  31     static char buff[2048];
 
  35     vsnprintf(buff, sizeof(buff), fmt, vl);
 
  40 //-----------------------------------------------------------------------------
 
  41 const char* Logger::logDate(time_t t) const
 
  45     const auto tt = localtime(&t);
 
  47     snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d",
 
  49              tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1,
 
  50              tt->tm_mday    < 10 ? "0" : "", tt->tm_mday,
 
  51              tt->tm_hour    < 10 ? "0" : "", tt->tm_hour,
 
  52              tt->tm_min     < 10 ? "0" : "", tt->tm_min,
 
  53              tt->tm_sec     < 10 ? "0" : "", tt->tm_sec);
 
  57 //-----------------------------------------------------------------------------
 
  58 void Logger::logString(const char* str) const
 
  60     if (!fileName.empty())
 
  62         auto f = fopen(fileName.c_str(), "at");
 
  66             fprintf(f, "%s", logDate(stgTime));
 
  68             fprintf(f, "%s", logDate(time(NULL)));
 
  71             fprintf(f, "%s", str);
 
  77             openlog("stg", LOG_NDELAY, LOG_USER);
 
  78             syslog(LOG_CRIT, "%s", str);
 
  84         openlog("stg", LOG_NDELAY, LOG_USER);
 
  85         syslog(LOG_CRIT, "%s", str);
 
  89 //-----------------------------------------------------------------------------
 
  90 void PluginLogger::operator()(const char * fmt, ...) const
 
  92     std::lock_guard<std::mutex> lock(m_mutex);
 
  94     static char buff[2029];
 
  98     vsnprintf(buff, sizeof(buff), fmt, vl);
 
 101     m_parent("[%s] %s", m_pluginName.c_str(), buff);
 
 103 //-----------------------------------------------------------------------------
 
 104 void PluginLogger::operator()(const std::string & line) const
 
 106     m_parent("[%s] %s", m_pluginName.c_str(), line.c_str());