~STG_LOGGER();
void SetLogFileName(const std::string & fn);
void operator()(const char * fmt, ...) const;
+ void operator()(const std::string & line) const { LogString(line.c_str()); }
private:
STG_LOGGER();
STG_LOGGER & operator=(const STG_LOGGER & rvalue);
const char * LogDate(time_t t) const;
+ void LogString(const char * str) const;
std::string fileName;
mutable pthread_mutex_t mutex;
public:
PLUGIN_LOGGER(const PLUGIN_LOGGER & rhs);
void operator()(const char * fmt, ...) const;
+ void operator()(const std::string & line) const;
private:
PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn);
vsnprintf(buff, sizeof(buff), fmt, vl);
va_end(vl);
-FILE * f;
+LogString(buff);
+}
+//-----------------------------------------------------------------------------
+const char * STG_LOGGER::LogDate(time_t t) const
+{
+static char s[32];
+if (t == 0)
+ t = time(NULL);
+
+struct tm * tt = localtime(&t);
+
+snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d",
+ tt->tm_year + 1900,
+ tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1,
+ tt->tm_mday < 10 ? "0" : "", tt->tm_mday,
+ tt->tm_hour < 10 ? "0" : "", tt->tm_hour,
+ tt->tm_min < 10 ? "0" : "", tt->tm_min,
+ tt->tm_sec < 10 ? "0" : "", tt->tm_sec);
+
+return s;
+}
+//-----------------------------------------------------------------------------
+void STG_LOGGER::LogString(const char * str) const
+{
if (!fileName.empty())
{
- f = fopen(fileName.c_str(), "at");
+ FILE * f = fopen(fileName.c_str(), "at");
if (f)
{
#ifdef STG_TIME
fprintf(f, "%s", LogDate(time(NULL)));
#endif
fprintf(f, " -- ");
- fprintf(f, "%s", buff);
+ fprintf(f, "%s", str);
fprintf(f, "\n");
fclose(f);
}
else
{
openlog("stg", LOG_NDELAY, LOG_USER);
- syslog(LOG_CRIT, "%s", buff);
+ syslog(LOG_CRIT, "%s", str);
closelog();
}
}
else
{
openlog("stg", LOG_NDELAY, LOG_USER);
- syslog(LOG_CRIT, "%s", buff);
+ syslog(LOG_CRIT, "%s", str);
closelog();
}
}
//-----------------------------------------------------------------------------
-const char * STG_LOGGER::LogDate(time_t t) const
-{
-static char s[32];
-if (t == 0)
- t = time(NULL);
-
-struct tm * tt = localtime(&t);
-
-snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d",
- tt->tm_year + 1900,
- tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1,
- tt->tm_mday < 10 ? "0" : "", tt->tm_mday,
- tt->tm_hour < 10 ? "0" : "", tt->tm_hour,
- tt->tm_min < 10 ? "0" : "", tt->tm_min,
- tt->tm_sec < 10 ? "0" : "", tt->tm_sec);
-
-return s;
-}
-//-----------------------------------------------------------------------------
PLUGIN_LOGGER::PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn)
: STG_LOGGER(),
pluginName(pn)
STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), buff);
}
//-----------------------------------------------------------------------------
+void PLUGIN_LOGGER::operator()(const std::string & line) const
+{
+STG_LOGGER::operator()("[%s] %s", pluginName.c_str(), line.c_str());
+}
+//-----------------------------------------------------------------------------
PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER & logger, const std::string & pluginName)
{
return PLUGIN_LOGGER(logger, pluginName);