You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gm...@apache.org on 2017/03/08 22:42:40 UTC

qpid-dispatch git commit: DISPATCH-597 - Changed time format of logged message to display YYYY-MM-DD and include milliseconds

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master dfab67e88 -> e53771a55


DISPATCH-597 - Changed time format of logged message to display YYYY-MM-DD and include milliseconds


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/e53771a5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/e53771a5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/e53771a5

Branch: refs/heads/master
Commit: e53771a5583ffcb9f80d52fbc59b50459298f9e4
Parents: dfab67e
Author: Ganesh Murthy <gm...@redhat.com>
Authored: Wed Mar 8 17:42:23 2017 -0500
Committer: Ganesh Murthy <gm...@redhat.com>
Committed: Wed Mar 8 17:42:23 2017 -0500

----------------------------------------------------------------------
 src/log.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e53771a5/src/log.c
----------------------------------------------------------------------
diff --git a/src/log.c b/src/log.c
index 7cdb483..812e848 100644
--- a/src/log.c
+++ b/src/log.c
@@ -53,7 +53,7 @@ struct qd_log_entry_t {
     int             level;
     char           *file;
     int             line;
-    time_t          time;
+    struct timeval  time;
     char            text[TEXT_MAX];
 };
 
@@ -82,6 +82,8 @@ DEQ_DECLARE(log_sink_t, log_sink_list_t);
 
 static log_sink_list_t sink_list = {0};
 
+const char *format = "%Y-%m-%d %H:%M:%S.%%03lu %z";
+
 static const char* SINK_STDOUT = "stdout";
 static const char* SINK_STDERR = "stderr";
 static const char* SINK_SYSLOG = "syslog";
@@ -298,8 +300,13 @@ static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry)
     if (default_bool(log_source->timestamp, default_log_source->timestamp)) {
         char buf[100];
         buf[0] = '\0';
-        ctime_r(&entry->time, buf);
-        buf[strlen(buf)-1] = '\0'; /* Get rid of trailng \n */
+
+        time_t sec = entry->time.tv_sec;
+        struct tm *local_tm = localtime(&sec);
+        char fmt[100];
+        strftime(fmt, sizeof fmt, format, local_tm);
+        snprintf(buf, 100, fmt, entry->time.tv_usec);
+
         aprintf(&begin, end, "%s ", buf);
     }
     aprintf(&begin, end, "%s (%s) %s", entry->module, level->name, entry->text);
@@ -402,7 +409,7 @@ void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, const char *fil
     entry->level  = level;
     entry->file   = file ? strdup(file) : 0;
     entry->line   = line;
-    time(&entry->time);
+    gettimeofday(&entry->time, NULL);
     vsnprintf(entry->text, TEXT_MAX, fmt, ap);
     write_log(source, entry);
 
@@ -443,7 +450,7 @@ PyObject *qd_log_recent_py(long limit) {
         PyList_SetItem(py_entry, i++, PyString_FromString(entry->text));
         PyList_SetItem(py_entry, i++, entry->file ? PyString_FromString(entry->file) : inc_none());
         PyList_SetItem(py_entry, i++, entry->file ? PyLong_FromLong(entry->line) : inc_none());
-        PyList_SetItem(py_entry, i++, PyLong_FromLongLong((PY_LONG_LONG)entry->time));
+        PyList_SetItem(py_entry, i++, PyLong_FromLongLong((PY_LONG_LONG)entry->time.tv_sec));
         assert(i == ENTRY_SIZE);
         if (PyErr_Occurred()) goto error;
         PyList_Insert(list, 0, py_entry);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org