Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support runtime change log level to higher verbosity level (IDFGH-3599) #5542

Closed
AxelLin opened this issue Jul 5, 2020 · 10 comments
Closed
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF

Comments

@AxelLin
Copy link
Contributor

AxelLin commented Jul 5, 2020

  • The problem:
    Currently the esp-idf only supports run-time lower verbosity level.
    So if build with CONFIG_LOG_DEFAULT_LEVEL to NONE, it's not possible to see any log by using esp_log_level_set.
    i.e. the CONFIG_LOG_DEFAULT_LEVEL also means the maximum log level.
    However, this is a very common use case that people don't want to show any log messages in release firmware but would like to
    enable log messages for debug when hitting issues.
    In current esp-idf, the only resolution is to rebuild with a debug firmware with higher CONFIG_LOG_DEFAULT_LEVEL.

  • The suggestion:
    Add CONFIG_LOG_MAX_LEVEL setting so people can decide it at compile-time and allow run-time set log level up to CONFIG_LOG_MAX_LEVEL.
    This way, it should be ok to set CONFIG_LOG_DEFAULT_LEVEL=NONE for release firmware and then enable log messages for debug.
    i.e. To allow runtime change log level to higher verbosity level for debug problem.

@AxelLin AxelLin added the Type: Feature Request Feature request for IDF label Jul 5, 2020
@github-actions github-actions bot changed the title Support runtime change log level to higher verbosity level Support runtime change log level to higher verbosity level (IDFGH-3599) Jul 5, 2020
@chegewara
Copy link
Contributor

chegewara commented Jul 5, 2020

This is already implemented, just naming is maybe confused to you.
CONFIG_LOG_DEFAULT_LEVEL does what you want to do with CONFIG_LOG_MAX_LEVEL and to control runtime you have esp_log_level_set. All you have to do is to add this line in app_main():
esp_log_level_set("*", ESP_LOG_NONE);
and all logs in app are turned off.

Remember that you have to rebuild all components when you change option in menuconfig, so it is so much easier to change 1 line in app_main rather than go to menuconfig, change option and recompile app.

@AxelLin
Copy link
Contributor Author

AxelLin commented Jul 5, 2020

This is already implemented, just naming is maybe confused to you.
CONFIG_LOG_DEFAULT_LEVEL does what you want to do with CONFIG_LOG_MAX_LEVEL and to control runtime you have esp_log_level_set. All you have to do is to add this line in app_main():
esp_log_level_set("*", ESP_LOG_NONE);
and all logs in app are turned off.

This is not what I'm asking for...
I want to build with CONFIG_LOG_DEFAULT_LEVEL=none, and also allows esp_log_level_set("*", ESP_LOG_ERROR);

see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/log.html#_CPPv417esp_log_level_setPKc15esp_log_level_t
Note that this function can not raise log level above the level set using CONFIG_LOG_DEFAULT_LEVEL setting in menuconfig.

@chegewara
Copy link
Contributor

When you set CONFIG_LOG_DEFAULT_LEVEL=none then logs are not included in binary file. It is meant to decrease binary size when you dont need then anymore.

This is not what I'm asking for...
I want to build with CONFIG_LOG_DEFAULT_LEVEL=none, and also allows esp_log_level_set("*", ESP_LOG_ERROR);

see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/log.html#_CPPv417esp_log_level_setPKc15esp_log_level_t
Note that this function can not raise log level above the level set using CONFIG_LOG_DEFAULT_LEVEL setting in menuconfig.

You can, but this wont make any difference since those logs are not part of binary, because default log level excluded them.

@AxelLin
Copy link
Contributor Author

AxelLin commented Jul 5, 2020

When you set CONFIG_LOG_DEFAULT_LEVEL=none then logs are not included in binary file. It is meant to decrease binary size when you dont need then anymore.

I'm aware about that.
So I would set CONFIG_LOG_MAX_LEVEL=ESP_LOG_DEBUG for debug build
and set CONFIG_LOG_MAX_LEVEL=ESP_LOG_WARN for release build.
And set CONFIG_LOG_DEFAULT_LEVEL=none for both cases.

This is not what I'm asking for...
I want to build with CONFIG_LOG_DEFAULT_LEVEL=none, and also allows esp_log_level_set("*", ESP_LOG_ERROR);
see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/log.html#_CPPv417esp_log_level_setPKc15esp_log_level_t
Note that this function can not raise log level above the level set using CONFIG_LOG_DEFAULT_LEVEL setting in menuconfig.

You can, but this wont make any difference since those logs are not part of binary, because default log level excluded them.

The problem of having CONFIG_LOG_DEFAULT_LEVEL=ESP_LOG_INFO and
calling esp_log_level_set("*", ESP_LOG_NONE) is it's too late to switch to ESP_LOG_NONE.
I still observe some booting messages during boot.
e.g.
I (546) cpu_start: Pro cpu up.
I (546) cpu_start: Application information:
I (546) cpu_start: Project name: my-app
I (548) cpu_start: App version: 1.2.3.4
I (553) cpu_start: Compile time: Jul 5 2020 19:51:03
I (559) cpu_start: ELF file SHA256: 1ce23f685baf66d3...
I (565) cpu_start: ESP-IDF: v4.2-dev-1905-g625bd5eb1806-dir
I (572) cpu_start: Starting app cpu, entry point is 0x40081950
....

@projectgus
Copy link
Contributor

Hi @AxelLin,

Thanks for explaining the request. Agree this would be useful. There are some considerations in implementing this, but I think we can probably find a way to make everything work smoothly.

I'm afraid that I can't give you an ETA on this feature, but we will look into it.

Angus

@AxelLin
Copy link
Contributor Author

AxelLin commented Jul 14, 2020

hi @projectgus

I though this could be quite easy:

  • At compile time: in menuconfig, set the verbosity level using the option :envvar:CONFIG_LOG_DEFAULT_LEVEL. All logging statements for verbosity levels higher than :envvar:CONFIG_LOG_DEFAULT_LEVEL will be removed by the preprocessor.

So define CONFIG_LOG_MAX_LEVEL to make preprocessor check CONFIG_LOG_MAX_LEVEL instead of CONFIG_LOG_DEFAULT_LEVEL, then it should work.

@AxelLin
Copy link
Contributor Author

AxelLin commented Feb 1, 2021

Hi @AxelLin,

Thanks for explaining the request. Agree this would be useful. There are some considerations in implementing this, but I think we can probably find a way to make everything work smoothly.

Hi @projectgus
It has been quite long time since I created this issue.
As my previous reply, I thought this is not too difficult, but I might be wrong.
Just wondering if any update?

@projectgus
Copy link
Contributor

@AxelLin Thanks for being patient, this does look like it's relatively small amount of work but we're also pretty busy around here. :).

The good news is that I have an implementation of this working, and it's currently in internal review. There are some tradeoffs so we might decide it needs further work, but hopefully not too long before it's available.

@espressif-bot espressif-bot added the Status: In Progress Work is in progress label Mar 22, 2021
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress labels May 3, 2021
espressif-bot pushed a commit that referenced this issue May 4, 2021
…evel

Tag filtering still doesn't work for this log type, but it will use the
default '*' log level instead of only the runtime level.

* Closes #2285
* Related to #5542
@projectgus
Copy link
Contributor

Thanks for being patient!

This option is available here now:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-log-maximum-level

@ClaesIvarsson
Copy link

boot.log
boot with verbose log level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

5 participants