(I submitted this issue to github a while ago but I thought this might be better asked here. https://github.com/espressif/esp-idf/issues/9851)
The documentation mentions that the logging level can be configured at compile time. I was expecting that the ESP_LOGx macro will be expanded to an empty statement if the level is not active, hence completely excluding it from the binary. But I am observing the macro to be expanded anyway and the filtering is done in runtime, adding to some overhead to process the code that should have been excluded from the build.
Below is the screenshot from my CLion IDE, My maximum log level was set to INFO but the verbose or debug level will still be expanded and compiled in my firmware.
Is this logging library working as expected? How could I prevent the verbose and debug logging from being compiled?
esp_log.h: How to exclude logging at compile time?
-
- Posts: 9739
- Joined: Thu Nov 26, 2015 4:08 am
Re: esp_log.h: How to exclude logging at compile time?
That is not done in the preprocessor, but by the compiler. The 'if (3 >= ESP_LOG_VERBOSE)' will always be expanded to a constant true or false by the compiler, and as such the code will compile to either the inner statement or no code at all, dependent on what the '3' value (which I assume comes from the max log level) is.
Re: esp_log.h: How to exclude logging at compile time?
I see. Thanks for the explanation!ESP_Sprite wrote: ↑Sun Sep 25, 2022 7:46 amThat is not done in the preprocessor, but by the compiler. The 'if (3 >= ESP_LOG_VERBOSE)' will always be expanded to a constant true or false by the compiler, and as such the code will compile to either the inner statement or no code at all, dependent on what the '3' value (which I assume comes from the max log level) is.
Who is online
Users browsing this forum: No registered users and 99 guests