Added log time support to the logger.
This commit is contained in:
parent
a6ccf28d54
commit
361e403936
|
@ -20,6 +20,8 @@
|
|||
#include "Version.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
// names of priorities
|
||||
static const char* g_priority[] = {
|
||||
|
@ -116,12 +118,6 @@ CLog::print(const char* file, int line, const char* fmt, ...) const
|
|||
|
||||
// compute prefix padding length
|
||||
char stack[1024];
|
||||
int pPad = g_priorityPad;
|
||||
if (file != NULL) {
|
||||
sprintf(stack, "%d", line);
|
||||
pPad += strlen(file) + 1 /* comma */ +
|
||||
strlen(stack) + 1 /* colon */ + 1 /* space */;
|
||||
}
|
||||
|
||||
// compute suffix padding length
|
||||
int sPad = m_maxNewlineLength;
|
||||
|
@ -134,7 +130,7 @@ CLog::print(const char* file, int line, const char* fmt, ...) const
|
|||
// try printing into the buffer
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int n = ARCH->vsnprintf(buffer + pPad, len - pPad - sPad, fmt, args);
|
||||
int n = ARCH->vsnprintf(buffer, len - sPad, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
// if the buffer wasn't big enough then make it bigger and try again
|
||||
|
@ -153,15 +149,26 @@ CLog::print(const char* file, int line, const char* fmt, ...) const
|
|||
}
|
||||
|
||||
// print the prefix to the buffer. leave space for priority label.
|
||||
char* message = buffer;
|
||||
char message[2048];
|
||||
if (file != NULL) {
|
||||
sprintf(buffer + g_priorityPad, "%s,%d:", file, line);
|
||||
buffer[pPad - 1] = ' ';
|
||||
|
||||
struct tm *tm;
|
||||
char tmp[220];
|
||||
time_t t;
|
||||
time(&t);
|
||||
tm = localtime(&t);
|
||||
sprintf(tmp, "%04i-%02i-%02iT%02i:%02i:%02i", tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
//strcpy(msg, tmp);
|
||||
|
||||
|
||||
sprintf(message, "%s %s: %s\n\t%s,%d", tmp, g_priority[priority], buffer, file, line);
|
||||
// buffer[pPad - 1] = ' ';
|
||||
|
||||
// discard file and line if priority < 0
|
||||
if (priority < 0) {
|
||||
/*if (priority < 0) {
|
||||
message += pPad - g_priorityPad;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// output buffer
|
||||
|
@ -249,17 +256,23 @@ CLog::output(int priority, char* msg) const
|
|||
assert(msg != NULL);
|
||||
|
||||
// insert priority label
|
||||
int n = -g_prioritySuffixLength;
|
||||
//int n = -g_prioritySuffixLength;
|
||||
/*
|
||||
if (priority >= 0) {
|
||||
|
||||
|
||||
n = strlen(g_priority[priority]);
|
||||
strcpy(msg + g_maxPriorityLength - n, g_priority[priority]);
|
||||
msg[g_maxPriorityLength + 0] = ':';
|
||||
msg[g_maxPriorityLength + 1] = ' ';
|
||||
msg[g_maxPriorityLength + 1] = ' ';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
// find end of message
|
||||
char* end = msg + g_priorityPad + strlen(msg + g_priorityPad);
|
||||
//char* end = msg + g_priorityPad + strlen(msg + g_priorityPad);
|
||||
char* end = msg+strlen(msg)-1;
|
||||
|
||||
// write to each outputter
|
||||
CArchMutexLock lock(m_mutex);
|
||||
|
@ -274,7 +287,7 @@ CLog::output(int priority, char* msg) const
|
|||
|
||||
// write message
|
||||
outputter->write(static_cast<ILogOutputter::ELevel>(priority),
|
||||
msg + g_maxPriorityLength - n);
|
||||
msg /*+ g_maxPriorityLength - n*/);
|
||||
}
|
||||
for (COutputterList::const_iterator index = m_outputters.begin();
|
||||
index != m_outputters.end(); ++index) {
|
||||
|
@ -286,7 +299,7 @@ CLog::output(int priority, char* msg) const
|
|||
|
||||
// write message and break out of loop if it returns false
|
||||
if (!outputter->write(static_cast<ILogOutputter::ELevel>(priority),
|
||||
msg + g_maxPriorityLength - n)) {
|
||||
msg /*+ g_maxPriorityLength - n*/)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue