ESP_LOG(I/W/E) vs printf for debug

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

ESP_LOG(I/W/E) vs printf for debug

Postby mikemoy » Thu Apr 12, 2018 12:59 pm

I notice that there are 2 camps for debugging via the serial port.
Those that use ESP_LOG(I/W/E), and those that use printf.
I am in the camp of printf because there is less typing involved to get the job done. But I am open to see if there is something I don't know about with using ESP_LOG(I/W/E).

Is this just a matter of preference, or is there a logical reason to use ESP_LOG(I/W/E) over "I've seen it done so that's why I do it" type mentality.

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: ESP_LOG(I/W/E) vs printf for debug

Postby ESP_krzychb » Thu Apr 12, 2018 1:44 pm

mikemoy wrote:Is this just a matter of preference, or is there a logical reason to use ESP_LOG(I/W/E) over "I've seen it done so that's why I do it" type mentality.
Hi mikemoy,

I think that for most of ad hoc debuging this it is a matter of preference with indication to use printf.

ESP_LOG(I/W/E) are intended to implement "permanent" logging functionality in the code and is also used in the ESP-IDF itself. Then depending on debugging scenario it is possible to globally or locally enable required verbosity levels of information to receive.

There are cases of ad hoc logging where ESP_LOG(I/W/E) is more appropriate, see Logging to Host via JTAG.

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: ESP_LOG(I/W/E) vs printf for debug

Postby mikemoy » Thu Apr 12, 2018 2:17 pm

For myself, I did not like the fact that through menuconfig I could only select one of the 5 options. They should let you select as many as you like. For instance, I could not select Error and Debug.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP_LOG(I/W/E) vs printf for debug

Postby kolban » Thu Apr 12, 2018 5:04 pm

I think the notion of logging levels including "encapsulated" logging levels is pretty well the common. For example, in Java land:

https://www.tutorialspoint.com/log4j/lo ... levels.htm

Maps:

ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: ESP_LOG(I/W/E) vs printf for debug

Postby meowsqueak » Mon Apr 16, 2018 7:01 am

I like the ESP_LOGx macros because you can enable/disable them at runtime. For example, hook up some appropriate MQTT topics and you've got yourself a run-time selectable debug log.

markevens
Posts: 38
Joined: Sat Aug 01, 2020 6:31 am

Re: ESP_LOG(I/W/E) vs printf for debug

Postby markevens » Mon Jun 06, 2022 5:51 am

Hello,
I write two very interesting stories on medium about "ESP_LOGx vs printf" and "Remote control on logs for enabling/disable logs". I think it's interesting for you to check this out.

ESP_LOGx vs printf
https://medium.com/@markevens36/esp-idf ... e24bd6fe78

Remote control on logs
https://medium.com/@markevens36/esp-idf ... 24acb28218

rdson@esp
Posts: 10
Joined: Wed Jun 15, 2022 8:41 am

Re: ESP_LOG(I/W/E) vs printf for debug

Postby rdson@esp » Tue Jul 05, 2022 7:48 am

I also figured out that printf can get buggy. I regularly miss text from a printf, partially or even totally while this seems to never happen on the ESP_LOGx ; I suppose this is related to thread behavior, printf most likely isn't thread safe whereas ESP_LOGx looks like to be.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 292 guests