Skip to content

Commit

Permalink
Print datetime when log to stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
  • Loading branch information
Jianhui Zhao committed Jan 20, 2019
1 parent 77572be commit fe4fb4e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* USA
*/

#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
Expand Down Expand Up @@ -55,6 +56,15 @@ static const char *log_ident()

static inline void log_write_stdout(int priority, const char *fmt, va_list ap)
{
time_t now;
struct tm tm;
char buf[32];

now = time(NULL);
localtime_r(&now, &tm);
strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", &tm);

fprintf(stderr, "%s ", buf);
vfprintf(stderr, fmt, ap);
}

Expand Down

0 comments on commit fe4fb4e

Please sign in to comment.