Logging to Serial

Frank B

Senior Member
The ESP family has a nice way to log debug information.

Where you used to work with "Serial.print(...)", new functions have been introduced (Serial.print should not be used anymore)

Logging is enabled with a #define selected in the Arduino menu:

2020-10-27 21_59_05-Cortana.png

There is then a set of functions:
log_e() - error (lowest)
log_w() - warning
log_i() - info
log_d() - debug
log_v() - verbose (highest)

these use the printf syntax. so for example
log_w("Temperature high: %d°C", temp);

I have recently learned about this, and it is a really useful feature,
Especially since it can be controlled anytime via the menu, and even the ESP core contributes a lot of these messages (depending on the DEBUG level)

An example looks like this:
(Log of my webradio-code)
Code:
21:51:15.620 -> [I][ESP32_Frank.ino:259] connectStream(): [HTTP] http://wdr-wdr2-rheinruhr.icecast.wdr.de/wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:15.620 -> [V][HTTPClient.cpp:235] beginInternal(): url: http://wdr-wdr2-rheinruhr.icecast.wdr.de/wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:15.673 -> [D][HTTPClient.cpp:276] beginInternal(): host: wdr-wdr2-rheinruhr.icecast.wdr.de port: 80 url: /wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:15.673 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /about.html
21:51:15.673 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /config.html
21:51:15.673 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /favicon.ico.gz
21:51:15.673 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /index.html
21:51:15.720 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /radio.css
21:51:15.720 -> [D][ESP32_Frank.ino:529] initWebServer(): Serve static: /stations.txt
21:51:15.774 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'HTTP/1.1 302 Found'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Server: nginx'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Date: Tue, 27 Oct 2020 20:51:13 GMT'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Content-Length: 0'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Connection: close'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Cache-Control: no-cache, no-store'
21:51:15.821 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Expires: Mon, 26 Jul 1997 05:00:00 GMT'
21:51:15.874 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Access-Control-Allow-Origin: *'
21:51:15.874 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type'
21:51:15.874 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Access-Control-Allow-Methods: GET, OPTIONS, HEAD'
21:51:15.874 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'Location: http://wdr-edge-2011-dus-lg-cdn.cast.addradio.de/wdr/wdr2/rheinruhr/mp3/128/stream.mp3?_art=dj0yJmlwPTk1LjIyMy41Ny4xNDUmaWQ9aWNzY3hsLXR2ZXM2amVuYiZ0PTE2MDM5MTgyNzMmcz03ODY2ZjI5YyNkNTczMjZhZTk3NDMyOGRhMDM2ZDhiNmVlZGI5OTkwNA'
21:51:15.921 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: ''
21:51:15.921 -> [D][HTTPClient.cpp:1158] handleHeaderResponse(): code: 302
21:51:15.921 -> [D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
21:51:15.921 -> [D][HTTPClient.cpp:383] disconnect(): tcp is closed
21:51:15.921 -> 
21:51:15.921 -> [I][ESP32_Frank.ino:259] connectStream(): [HTTP] http://wdr-edge-2011-dus-lg-cdn.cast.addradio.de/wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:15.921 -> [V][HTTPClient.cpp:235] beginInternal(): url: http://wdr-edge-2011-dus-lg-cdn.cast.addradio.de/wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:15.974 -> [D][HTTPClient.cpp:276] beginInternal(): host: wdr-edge-2011-dus-lg-cdn.cast.addradio.de port: 80 url: /wdr/wdr2/rheinruhr/mp3/128/stream.mp3
21:51:16.021 -> [D][HTTPClient.cpp:1025] connect():  connected to wdr-edge-2011-dus-lg-cdn.cast.addradio.de:80
21:51:16.075 -> [V][HTTPClient.cpp:1123] handleHeaderResponse(): RX: 'HTTP/1.0 200 OK'
You see the debug-level, the source file, the name of the function, line number, and the information itself. Since I switched to "Verbose" here, there are quite a lot of them - but you can always switch down the level.

@Paul:
What do you think?
 
Last edited:
Back
Top