This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 8118f3545 log_console: Add option to print time stamp as clock time
8118f3545 is described below
commit 8118f35457dc7d38813513fe6794046a1e11cde6
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Apr 8 22:01:13 2025 +0200
log_console: Add option to print time stamp as clock time
When LOG_CONSOLE_PRETTY_WITH_TIMESTAMP is set to 1 timestamp
of the logs is print in human readable format instead of
really big numbers.
Signed-off-by: Jerzy Kasenberg <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
sys/log/full/pkg.yml | 1 +
sys/log/full/src/log_console.c | 15 ++++++++++++++-
sys/log/full/syscfg.yml | 5 +++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index fe6f8c8b2..363a3dc1c 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -29,6 +29,7 @@ pkg.deps:
- "@apache-mynewt-core/sys/flash_map"
- "@apache-mynewt-core/sys/log/common"
- "@apache-mynewt-core/util/cbmem"
+ - "@apache-mynewt-core/time/datetime"
pkg.deps.LOG_FCB:
- "@apache-mynewt-core/hw/hal"
diff --git a/sys/log/full/src/log_console.c b/sys/log/full/src/log_console.c
index 13e7e1169..b2a30ae4f 100644
--- a/sys/log/full/src/log_console.c
+++ b/sys/log/full/src/log_console.c
@@ -26,6 +26,7 @@
#include "log/log.h"
#include "tinycbor/cbor.h"
#include "tinycbor/cbor_buf_reader.h"
+#include "datetime/datetime.h"
static int
log_console_dump_cbor_entry(const void *dptr, uint16_t len)
@@ -182,7 +183,19 @@ log_console_print_hdr(const struct log_entry_hdr *hdr)
level_str = level_str_buf;
}
- if (MYNEWT_VAL(LOG_CONSOLE_PRETTY_WITH_TIMESTAMP)) {
+ if (MYNEWT_VAL(LOG_CONSOLE_PRETTY_WITH_TIMESTAMP) &&
+ MYNEWT_VAL(LOG_CONSOLE_PRETTY_TIMESTAMP_CLOCK)) {
+ struct os_timeval tv = {
+ .tv_usec = (unsigned int)hdr->ue_ts % 1000000,
+ .tv_sec = (unsigned int)(hdr->ue_ts / 1000000),
+ };
+ struct clocktime ct;
+ timeval_to_clocktime(&tv, NULL, &ct);
+ console_printf("[%d-%02d-%02dT%02d:%02d:%02d.%06u][%s%7s%s][%s]%s ",
+ ct.year, ct.mon, ct.day,
+ ct.hour, ct.min, ct.sec, ct.usec,
+ color, module_name, color_off, level_str,
image_hash_str);
+ } else if (MYNEWT_VAL(LOG_CONSOLE_PRETTY_WITH_TIMESTAMP)) {
unsigned int us = (unsigned int)hdr->ue_ts % 1000000;
unsigned int s = (unsigned int)(hdr->ue_ts / 1000000);
console_printf("[%u.%06u][%s%7s%s][%s]%s ", s, us, color, module_name,
color_off, level_str, image_hash_str);
diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml
index 7170e91ed..dc228d218 100644
--- a/sys/log/full/syscfg.yml
+++ b/sys/log/full/syscfg.yml
@@ -52,6 +52,11 @@ syscfg.defs:
Turned off by default when CONSOLE_TICKS is on.
value: 1
+ LOG_CONSOLE_PRETTY_TIMESTAMP_CLOCK:
+ description: >
+ Print timestamp as time yyyy-mm-ddThh:ss:mm.uuuuuu.
+ value: 0
+
LOG_FLAGS_IMAGE_HASH:
description: >
Enable logging of the first 4 bytes of the image hash. 0 - disable;