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

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

Patch that adds timestamps to log messages, updated 2012-02-10T10:10:10Z

  • src/util.c

    From be5b2fee90a0b76216a288cb0f021588b1a72168 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..315c4a3 100644
    a b  
    2121#include <stdio.h>
    2222#include <unistd.h>
    2323#include <assert.h>
     24#include <time.h>
    2425
    2526#include <event2/dns.h>
    2627#ifndef _WIN32
    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, sizeof(ts), "%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