Add a nice timestamp to the output of log file messages
This commit is contained in:
parent
9c3a85f824
commit
340c72f9e2
|
@ -113,6 +113,8 @@ void log_func_file(int level, const char* fmt, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
int ret;
|
int ret;
|
||||||
const char* level_str;
|
const char* level_str;
|
||||||
|
char timebuf[40];
|
||||||
|
time_t t;
|
||||||
|
|
||||||
/* choose appropriate line description */
|
/* choose appropriate line description */
|
||||||
switch(level) {
|
switch(level) {
|
||||||
|
@ -127,11 +129,15 @@ void log_func_file(int level, const char* fmt, ...)
|
||||||
default: level_str = "?BUG?"; break;
|
default: level_str = "?BUG?"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* construct timestamp */
|
||||||
|
time(&t);
|
||||||
|
strftime(timebuf, sizeof(timebuf), "%FT%H:%M:%S", gmtime(&t));
|
||||||
|
|
||||||
/* print to file descriptor */
|
/* print to file descriptor */
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
if(safe_write_fixed(STDERR_FILENO, level_str, 5) != 5) ret = -1;
|
ret = dprintf(log_func_fd, "%s %s ", timebuf, level_str);
|
||||||
ret = vdprintf(log_func_fd, fmt, va);
|
if(ret != -1) ret = vdprintf(log_func_fd, fmt, va);
|
||||||
if(safe_write_fixed(STDERR_FILENO, "\n", 1) != 1) ret = -1;
|
if(ret != -1 && safe_write_fixed(log_func_fd, "\n", 1) != 1) ret = -1;
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
/* report errors */
|
/* report errors */
|
||||||
|
|
|
@ -117,6 +117,7 @@ int main(int argc, char* argv[])
|
||||||
LOG_ANYWHERE("Error logging to file `%s' (%m).", log_argument);
|
LOG_ANYWHERE("Error logging to file `%s' (%m).", log_argument);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
log_destination_set(log_destination_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* daemonise? */
|
/* daemonise? */
|
||||||
|
|
Loading…
Reference in New Issue