8 extern const volatile time_t stgTime;
10 //-----------------------------------------------------------------------------
11 STG_LOGGER & GetStgLogger()
13 static STG_LOGGER logger;
16 //-----------------------------------------------------------------------------
17 STG_LOGGER::STG_LOGGER()
20 pthread_mutex_init(&mutex, NULL);
22 //-----------------------------------------------------------------------------
23 STG_LOGGER::~STG_LOGGER()
25 pthread_mutex_destroy(&mutex);
27 //-----------------------------------------------------------------------------
28 void STG_LOGGER::SetLogFileName(const std::string & fn)
30 STG_LOGGER_LOCKER lock(&mutex);
33 //-----------------------------------------------------------------------------
34 void STG_LOGGER::operator()(const char * fmt, ...)
36 STG_LOGGER_LOCKER lock(&mutex);
42 vsnprintf(buff, sizeof(buff), fmt, vl);
46 if (!fileName.empty())
48 f = fopen(fileName.c_str(), "at");
52 fprintf(f, "%s", LogDate(stgTime));
54 fprintf(f, "%s", LogDate(time(NULL)));
57 fprintf(f, "%s", buff);
63 openlog("stg", LOG_NDELAY, LOG_USER);
64 syslog(LOG_CRIT, "%s", buff);
70 openlog("stg", LOG_NDELAY, LOG_USER);
71 syslog(LOG_CRIT, "%s", buff);
75 //-----------------------------------------------------------------------------
76 const char * STG_LOGGER::LogDate(time_t t)
82 struct tm * tt = localtime(&t);
84 snprintf(s, 32, "%d-%s%d-%s%d %s%d:%s%d:%s%d",
86 tt->tm_mon + 1 < 10 ? "0" : "", tt->tm_mon + 1,
87 tt->tm_mday < 10 ? "0" : "", tt->tm_mday,
88 tt->tm_hour < 10 ? "0" : "", tt->tm_hour,
89 tt->tm_min < 10 ? "0" : "", tt->tm_min,
90 tt->tm_sec < 10 ? "0" : "", tt->tm_sec);
94 //-----------------------------------------------------------------------------