This patch is used to add timestamp and process id to log messages when logging
messages to a file.

Signed-off-by: QI Fuli <qi.f...@jp.fujitsu.com>
---
 ndctl/monitor.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index 2f3d751..d29e378 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -84,6 +84,8 @@ static void log_file(struct ndctl_ctx *ctx, int priority, 
const char *file,
 {
        FILE *f;
        char *buf;
+       struct timespec ts;
+       char timestamp[32];
 
        if (vasprintf(&buf, format, args) < 0) {
                fail("vasprintf error\n");
@@ -99,7 +101,14 @@ static void log_file(struct ndctl_ctx *ctx, int priority, 
const char *file,
                notice(ctx, "%s\n", buf);
                goto end;
        }
-       fprintf(f, "%s", buf);
+
+       if (priority != LOG_NOTICE) {
+               clock_gettime(CLOCK_REALTIME, &ts);
+               sprintf(timestamp, "%10ld.%09ld", ts.tv_sec, ts.tv_nsec);
+               fprintf(f, "[%s] [%d] %s", timestamp, getpid(), buf);
+       } else
+               fprintf(f, "%s", buf);
+
        fflush(f);
        fclose(f);
 end:
-- 
2.18.0


_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to