1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Put the time in the log messages

This commit is contained in:
Nicolas Viennot 2013-06-14 02:34:10 -04:00
parent fb733d9433
commit 2e69b5c692

12
log.c
View File

@ -80,12 +80,22 @@ log_close(void)
void void
log_vwrite(const char *msg, va_list ap) log_vwrite(const char *msg, va_list ap)
{ {
char time_str[100];
time_t now;
struct tm *tm;
char *fmt; char *fmt;
if (log_file == NULL) if (log_file == NULL)
return; return;
if (asprintf(&fmt, "[%s] %s\n", tmate_session_token, msg) == -1) /* XXX Should we do UTC instead of local time? */
now = time(NULL);
tm = localtime(&now);
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", tm);
if (asprintf(&fmt, "%s [%s] %s\n", time_str, tmate_session_token, msg) == -1)
exit(1); exit(1);
if (vfprintf(log_file, fmt, ap) == -1) if (vfprintf(log_file, fmt, ap) == -1)
exit(1); exit(1);