Easy to read tiemstamp in log

parent a7307747
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <time.h>
#define __USE_GNU /* for *_CLOEXEC */ #define __USE_GNU /* for *_CLOEXEC */
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#define LXC_LOG_PREFIX_SIZE 32 #define LXC_LOG_PREFIX_SIZE 32
#define LXC_LOG_BUFFER_SIZE 512 #define LXC_LOG_BUFFER_SIZE 512
#define LXC_LOG_DATEFOMAT_SIZE 15
int lxc_log_fd = -1; int lxc_log_fd = -1;
int lxc_quiet_specified; int lxc_quiet_specified;
...@@ -69,7 +71,9 @@ static int log_append_stderr(const struct lxc_log_appender *appender, ...@@ -69,7 +71,9 @@ static int log_append_stderr(const struct lxc_log_appender *appender,
static int log_append_logfile(const struct lxc_log_appender *appender, static int log_append_logfile(const struct lxc_log_appender *appender,
struct lxc_log_event *event) struct lxc_log_event *event)
{ {
char date[LXC_LOG_DATEFOMAT_SIZE] = "20150427012246";
char buffer[LXC_LOG_BUFFER_SIZE]; char buffer[LXC_LOG_BUFFER_SIZE];
const struct tm *t;
int n; int n;
int ms; int ms;
int fd_to_use = -1; int fd_to_use = -1;
...@@ -85,11 +89,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -85,11 +89,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
if (fd_to_use == -1) if (fd_to_use == -1)
return 0; return 0;
t = localtime(&event->timestamp.tv_sec);
strftime(date, sizeof(LXC_LOG_DATEFOMAT_SIZE), "%Y%m%d%H%M%S", t);
ms = event->timestamp.tv_usec / 1000; ms = event->timestamp.tv_usec / 1000;
n = snprintf(buffer, sizeof(buffer), n = snprintf(buffer, sizeof(buffer),
"%15s %10ld.%03d %-8s %s - %s:%s:%d - ", "%15s %10s.%03d %-8s %s - %s:%s:%d - ",
log_prefix, log_prefix,
event->timestamp.tv_sec, date,
ms, ms,
lxc_log_priority_to_string(event->priority), lxc_log_priority_to_string(event->priority),
event->category, event->category,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment