* [PATCH] log: add timestamp for log
@ 2023-03-03 9:54 luzhipeng
0 siblings, 0 replies; 3+ messages in thread
From: luzhipeng @ 2023-03-03 9:54 UTC (permalink / raw)
To: dev; +Cc: thomas, zhipeng Lu
From: zhipeng Lu <luzhipeng@cestc.cn>
add timestamp for log
Signed-off-by: zhipeng Lu <luzhipeng@cestc.cn>
---
lib/eal/common/eal_common_log.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index bd7b188ceb..2b481116b6 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -480,6 +480,27 @@ rte_log_dump(FILE *f)
}
}
+/* get timestamp*/
+void
+rte_log_get_timestamp_prefix(char *buf, int buf_size)
+{
+ struct tm *info;
+ char date[24];
+ struct timespec ts;
+ long usec;
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ info = localtime(&ts.tv_sec);
+ usec = ts.tv_nsec / 1000;
+ if (info == NULL) {
+ snprintf(buf, buf_size, "[%s.%06ld] ", "unknown date", usec);
+ return;
+ }
+
+ strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", info);
+ snprintf(buf, buf_size, "[%s.%06ld] ", date, usec);
+}
+
/*
* Generates a log message The message will be sent in the stream
* defined by the previous call to rte_openlog_stream().
@@ -489,6 +510,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
{
FILE *f = rte_log_get_stream();
int ret;
+ char timestamp[64];
if (logtype >= rte_logs.dynamic_types_len)
return -1;
@@ -498,7 +520,8 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
/* save loglevel and logtype in a global per-lcore variable */
RTE_PER_LCORE(log_cur_msg).loglevel = level;
RTE_PER_LCORE(log_cur_msg).logtype = logtype;
-
+ rte_log_get_timestamp_prefix(timestamp, sizeof(timestamp));
+ fprintf(f,"%s ",timestamp);
ret = vfprintf(f, format, ap);
fflush(f);
return ret;
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] log: add timestamp for log
@ 2023-03-04 3:04 luzhipeng
0 siblings, 0 replies; 3+ messages in thread
From: luzhipeng @ 2023-03-04 3:04 UTC (permalink / raw)
To: dev; +Cc: thomas, zhipeng Lu
From: zhipeng Lu <luzhipeng@cestc.cn>
add timestamp for log
Signed-off-by: zhipeng Lu <luzhipeng@cestc.cn>
---
lib/eal/common/eal_common_log.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index bd7b188ceb..2b481116b6 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -480,6 +480,27 @@ rte_log_dump(FILE *f)
}
}
+/* get timestamp*/
+void
+rte_log_get_timestamp_prefix(char *buf, int buf_size)
+{
+ struct tm *info;
+ char date[24];
+ struct timespec ts;
+ long usec;
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ info = localtime(&ts.tv_sec);
+ usec = ts.tv_nsec / 1000;
+ if (info == NULL) {
+ snprintf(buf, buf_size, "[%s.%06ld] ", "unknown date", usec);
+ return;
+ }
+
+ strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", info);
+ snprintf(buf, buf_size, "[%s.%06ld] ", date, usec);
+}
+
/*
* Generates a log message The message will be sent in the stream
* defined by the previous call to rte_openlog_stream().
@@ -489,6 +510,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
{
FILE *f = rte_log_get_stream();
int ret;
+ char timestamp[64];
if (logtype >= rte_logs.dynamic_types_len)
return -1;
@@ -498,7 +520,8 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
/* save loglevel and logtype in a global per-lcore variable */
RTE_PER_LCORE(log_cur_msg).loglevel = level;
RTE_PER_LCORE(log_cur_msg).logtype = logtype;
-
+ rte_log_get_timestamp_prefix(timestamp, sizeof(timestamp));
+ fprintf(f,"%s ",timestamp);
ret = vfprintf(f, format, ap);
fflush(f);
return ret;
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] log: add timestamp for log
@ 2023-03-03 10:02 luzhipeng
0 siblings, 0 replies; 3+ messages in thread
From: luzhipeng @ 2023-03-03 10:02 UTC (permalink / raw)
To: dev; +Cc: thomas, zhipeng Lu
From: zhipeng Lu <luzhipeng@cestc.cn>
add timestamp for log
Signed-off-by: zhipeng Lu <luzhipeng@cestc.cn>
---
lib/eal/common/eal_common_log.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c
index bd7b188ceb..2b481116b6 100644
--- a/lib/eal/common/eal_common_log.c
+++ b/lib/eal/common/eal_common_log.c
@@ -480,6 +480,27 @@ rte_log_dump(FILE *f)
}
}
+/* get timestamp*/
+void
+rte_log_get_timestamp_prefix(char *buf, int buf_size)
+{
+ struct tm *info;
+ char date[24];
+ struct timespec ts;
+ long usec;
+
+ clock_gettime(CLOCK_REALTIME, &ts);
+ info = localtime(&ts.tv_sec);
+ usec = ts.tv_nsec / 1000;
+ if (info == NULL) {
+ snprintf(buf, buf_size, "[%s.%06ld] ", "unknown date", usec);
+ return;
+ }
+
+ strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", info);
+ snprintf(buf, buf_size, "[%s.%06ld] ", date, usec);
+}
+
/*
* Generates a log message The message will be sent in the stream
* defined by the previous call to rte_openlog_stream().
@@ -489,6 +510,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
{
FILE *f = rte_log_get_stream();
int ret;
+ char timestamp[64];
if (logtype >= rte_logs.dynamic_types_len)
return -1;
@@ -498,7 +520,8 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
/* save loglevel and logtype in a global per-lcore variable */
RTE_PER_LCORE(log_cur_msg).loglevel = level;
RTE_PER_LCORE(log_cur_msg).logtype = logtype;
-
+ rte_log_get_timestamp_prefix(timestamp, sizeof(timestamp));
+ fprintf(f,"%s ",timestamp);
ret = vfprintf(f, format, ap);
fflush(f);
return ret;
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-06 7:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 9:54 [PATCH] log: add timestamp for log luzhipeng
2023-03-03 10:02 luzhipeng
2023-03-04 3:04 luzhipeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).