How to use ARDUHAL_SHORT_LOG_FORMAT

Bascy65
Posts: 5
Joined: Tue Dec 26, 2017 2:32 pm

How to use ARDUHAL_SHORT_LOG_FORMAT

Postby Bascy65 » Thu Apr 28, 2022 7:20 pm

In esp_hal_log.h there are some changes to logging format, esp adding a millisecond timestamp by default
as I already have a logging extension in place that outputs actual timestamp in stead of milliseconds since last boot, I want to ignore this change.

esp-hal-Log.h does contain a simple format in a macro called ARDUHAL_SHORT_LOG_FORMAT but I can;t seem to find a way to make the logging use this format in stead of the ARDUHAL_LOG_FORMAT used now.

How can I do this?

matsumoto
Posts: 1
Joined: Fri Oct 14, 2022 3:13 pm

Re: How to use ARDUHAL_SHORT_LOG_FORMAT

Postby matsumoto » Fri Oct 14, 2022 3:51 pm

Hi,

I was wondering the same and I found one solution. I didn't wanted to change the file esp_hal_log.h, so instead I just added this into my own application file (for example main.cpp):
  1. #include <esp32-hal-log.h>
  2. #undef ARDUHAL_LOG_FORMAT
  3. #define ARDUHAL_LOG_FORMAT(letter, format)  ARDUHAL_SHORT_LOG_FORMAT(letter, format)

You also can redefine it to anything else you want. For example just remove the time:
  1. #include <esp32-hal-log.h>
  2. #undef ARDUHAL_LOG_FORMAT
  3. #define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__
It works at least for my code but not for the code that uses the logging which is called to start my code (the part before setup() and loop()).

You could also change the code directly in esp_hal_log.h but then you might need to remember it when this part is updated or you hand the code to somebody else who does not have the change in the library.

Who is online

Users browsing this forum: Baidu [Spider], Basalt, PepeTheGreat and 52 guests