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

mikemoy
Posts: 441
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: 257
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: 441
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: 144
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.

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 25 guests