How to show Date and Time in log?
-
- Posts: 2
- Joined: Fri Dec 09, 2022 9:16 pm
How to show Date and Time in log?
I searched the documentation and there is no mention on how to view the date and time in log. The current second timestamp is unreadable.
Re: How to show Date and Time in log?
There's a setting in the SDK config for this. Just run menuconfig to change it. Of course the date/time won't be correct unless you have a mechanism in your app to set it either manually or from, say, an NTP server.
In my application log messages, since I don't use actual date/time, I include an elapsed time since boot in hh:mm:ss format which I derive from the ms since boot number.
In my application log messages, since I don't use actual date/time, I include an elapsed time since boot in hh:mm:ss format which I derive from the ms since boot number.
-
- Posts: 2
- Joined: Fri Dec 09, 2022 9:16 pm
Re: How to show Date and Time in log?
Yes, there are two options:
Unfortunately, both of them display a number; I would like something like "YYYY-MM-DD hh:mm:ss"Milliseconds Since Boot (LOG_TIMESTAMP_SOURCE_RTOS)
System Time (LOG_TIMESTAMP_SOURCE_SYSTEM)
Re: How to show Date and Time in log?
The ESP32 only knows elapsed time either milliseconds since boot (if you use LOG_TIMESTAMP_SOURCE_RTOS) or HH:MM:SS.SSS since the last power up (if you use LOG_TIMESTAMP_SOURCE_SYSTEM). It has no reference point for the date. You'd have to establish that on every power cycle at least. There will also be some time drift due to the crystal frequency tolerance/variation.
If you want to display an accurate date/time on log messages, you will probably have to roll your own logger, perhaps modify the one that ESP-IDF provides. Then you can hook it into whatever time sync scheme you devise. It may be just a matter of writing your own version of esp_log_system_timestamp.
If you want to display an accurate date/time on log messages, you will probably have to roll your own logger, perhaps modify the one that ESP-IDF provides. Then you can hook it into whatever time sync scheme you devise. It may be just a matter of writing your own version of esp_log_system_timestamp.
Re: How to show Date and Time in log?
One method to do this is to edit the original routine to be weakly linked (STM do this extensively in their APIs), thus:
[esp32/esp-idf_v5.3/components/log/log_freertos.c]
// plc 2024Nov17 - make weak linkage
#pragma weak esp_log_system_timestamp
char *esp_log_system_timestamp(void)
then you can just copy and paste the original to your code, modify the format to your specific requirements and the linker will favour your version over the weak one.
The downside is that when you update to the latest esp-idf you will have to remember to reedit the pragma (I pur a comment on my copy to remind me what I did)
Enjoy
[esp32/esp-idf_v5.3/components/log/log_freertos.c]
// plc 2024Nov17 - make weak linkage
#pragma weak esp_log_system_timestamp
char *esp_log_system_timestamp(void)
then you can just copy and paste the original to your code, modify the format to your specific requirements and the linker will favour your version over the weak one.
The downside is that when you update to the latest esp-idf you will have to remember to reedit the pragma (I pur a comment on my copy to remind me what I did)
Enjoy
Who is online
Users browsing this forum: Bing [Bot] and 257 guests