Ticket #5069: 0001-Add-timestamps-to-log-messages.patch

File 0001-Add-timestamps-to-log-messages.patch, 1.0 KB (added by karsten, 8 years ago)

Patch that adds timestamps to log messages

  • src/util.c

    From f9dd022c573559329ea37d7c3c51021896084226 Mon Sep 17 00:00:00 2001
    From: Karsten Loesing <karsten.loesing@gmx.net>
    Date: Fri, 10 Feb 2012 10:08:26 +0100
    Subject: [PATCH] Add timestamps to log messages.
    
    Timestamps are in ISO 8601 format and in UTC.  Fixes #5069.
    ---
     src/util.c |    8 +++++++-
     1 files changed, 7 insertions(+), 1 deletions(-)
    
    diff --git a/src/util.c b/src/util.c
    index 000bf85..3a4b8b8 100644
    a b  
    1515 **/
    1616
    1717#include "util.h"
     18#include "time.h"
    1819
    1920#include <errno.h>
    2021#include <fcntl.h>
    logv(int severity, const char *format, va_list ap) 
    519520  int r=0;
    520521  char buf[MAX_LOG_ENTRY];
    521522
     523  time_t now = time(NULL);
     524  struct tm *nowtm = gmtime(&now);
     525  char ts[21];
    522526  size_t buflen = MAX_LOG_ENTRY-2;
    523527
    524   r = obfs_snprintf(buf, buflen, "[%s] ", sev_to_string(severity));
     528  strftime(ts, 21, "%Y-%m-%dT%H:%M:%SZ", nowtm);
     529  r = obfs_snprintf(buf, buflen, "%s [%s] ", ts,
     530                    sev_to_string(severity));
    525531  if (r < 0)
    526532    n = strlen(buf);
    527533  else