Added timestamp to log file headers and to the beginning of each line. Removed additional line feeds.
Example: SkySQL MaxScale Sat Jul 27 12:13:10 2013 ------------------------------------------ 2013 07/27 12:13:10 Loaded module testroute: V1.0.0 2013 07/27 12:13:10 Initialise debug CLI router module V1.0.1. 2013 07/27 12:13:10 Loaded module debugcli: V1.0.1
This commit is contained in:
@ -31,6 +31,7 @@
|
||||
#define MAX_SUFFIXLEN 250
|
||||
#define MAX_PATHLEN 512
|
||||
#define MAXNBLOCKBUFS 10
|
||||
|
||||
/**
|
||||
* BUFSIZ comes from the system. It equals with block size or
|
||||
* its multiplication.
|
||||
@ -500,10 +501,14 @@ static int logmanager_write_log(
|
||||
char* str,
|
||||
va_list valist)
|
||||
{
|
||||
logfile_t* lf;
|
||||
char* wp;
|
||||
int err = 0;
|
||||
blockbuf_t* bb;
|
||||
logfile_t* lf;
|
||||
char* wp;
|
||||
int err = 0;
|
||||
blockbuf_t* bb;
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
const char* timestamp_formatstr = "%04d %02d/%02d %02d:%02d:%02d ";
|
||||
const int timestamp_len = 4+1+2+1+2+1+2+1+2+1+2+3;
|
||||
|
||||
CHK_LOGMANAGER(lm);
|
||||
|
||||
@ -543,14 +548,31 @@ static int logmanager_write_log(
|
||||
* Seek write position and register to block buffer.
|
||||
* Then print formatted string to write position.
|
||||
*/
|
||||
wp = blockbuf_get_writepos(&bb, id, str_len, flush);
|
||||
|
||||
wp = blockbuf_get_writepos(&bb, id, timestamp_len-1+str_len, flush);
|
||||
/** Generate timestamp */
|
||||
t = time(NULL);
|
||||
tm = *(localtime(&t));
|
||||
snprintf(wp,
|
||||
timestamp_len,
|
||||
timestamp_formatstr,
|
||||
tm.tm_year+1900,
|
||||
tm.tm_mon+1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
/**
|
||||
* Write next string to overwrite terminating null character of the
|
||||
* timestamp string.
|
||||
*/
|
||||
if (use_valist) {
|
||||
vsnprintf(wp, str_len, str, valist);
|
||||
vsnprintf(wp+timestamp_len-1, str_len, str, valist);
|
||||
} else {
|
||||
snprintf(wp, str_len, str);
|
||||
snprintf(wp+timestamp_len-1, str_len, str);
|
||||
}
|
||||
if (wp[timestamp_len-1+str_len-2] != '\n') {
|
||||
wp[timestamp_len-1+str_len-1]='\n';
|
||||
}
|
||||
wp[str_len-1]='\n';
|
||||
|
||||
/** lock-free unregistration, includes flush if bb_isfull */
|
||||
blockbuf_unregister(bb);
|
||||
|
@ -40,9 +40,10 @@ static void* thr_run_morelog(void* data);
|
||||
#define NTHR 256
|
||||
#define NITER 100
|
||||
|
||||
#if 0
|
||||
#define TEST1
|
||||
#define TEST2
|
||||
|
||||
#endif
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int err = 0;
|
||||
@ -54,6 +55,8 @@ int main(int argc, char* argv[])
|
||||
simple_mutex_t* mtx;
|
||||
size_t nactive;
|
||||
thread_t* thr[NTHR];
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
|
||||
i = atexit(skygw_logmanager_exit);
|
||||
|
||||
@ -64,6 +67,18 @@ int main(int argc, char* argv[])
|
||||
r = skygw_logmanager_init(NULL, argc, argv);
|
||||
ss_dassert(r);
|
||||
|
||||
t = time(NULL);
|
||||
tm = *(localtime(&t));
|
||||
err = skygw_log_write_flush(NULL,
|
||||
LOGFILE_ERROR,
|
||||
"%04d %02d/%02d %02d.%02d.%02d",
|
||||
tm.tm_year+1900,
|
||||
tm.tm_mon+1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
|
||||
skygw_logmanager_init(NULL, argc, argv);
|
||||
logstr = ("First write with flush.");
|
||||
err = skygw_log_write_flush(NULL, LOGFILE_ERROR, logstr);
|
||||
|
Reference in New Issue
Block a user