-
Notifications
You must be signed in to change notification settings - Fork 53
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
Where to set the logging level at compile-time? #222
Comments
First you need to answer the following question: Log level of "what", as there are exist a bunch of different loglevel's for different parts. For example 2nd stage bootloader and your application code in general having different knob's. For most of the IDF logging you can set different sdkconfig levels depending on the level. Have a look at this options. For example to set the default log level to error only you can add You can have different sdkconfig files for different esp variants and profiles. For info look at our build option chapter in esp-idf-sys and check the official docu on that topic. If you want to reduce what is actually binary size you can also use the CONFIG_LOG_MAXIMUM_LEVEL sdkconfig option. For other runtime logging log level changes you might want to you can simply initialize the EspLogger and set its target with something like this esp_idf_svc::log::EspLogger::initialize_default();
let logger = esp_idf_svc::log::EspLogger;
logger.set_target_level("*", LevelFilter::Trace).unwrap(); |
I meant the logging level of the logs I print with the
Also your solution does not seem to effectively set the target level. The following code does not print anything.
|
Note that "configuration files" on embedded is always compile-time as well. Just mentioning. But indeed, kind of "less" hard-coded. :)
I've tried to explain why below... @victorbnl @Vollbrecht Let me try to summarize the status quo - as much as I understand it myself, as I feel @Vollbrecht - feel free to correct if you spot any inconsistencies It is easiest to split the notion of logging into two aspects:
(Rust code only) Logging from Rust (with the
|
Thank you very much, very interesting explanation! So as per your instructions I tried the following steps
And when I say the following steps I mean I did them all then ran the projects, with all the changes done. And after that, my debug messages still don’t get logged. |
There was some weird cludge w.r.t. how |
And also Once these trigger, you can reduce from there. |
Overall your summary is correct, though the initial question was how to set it for different profiles. E.g set a different level for a release build compared to a debug build, or set a different level for lets say building against esp32c3 compared to building against a esp32 all at compile time. I linked it in my initial answer but just to make it super clear by explicitly stating how one can do that:
Nothing more is needed in this case, from a "global" app logging perspective. Also no other additions are needed inside your rust code. We automatically detect different sdkconfigs and apply them accordingly. So you now can run |
So now I have the following:
Still no debug logs printed. |
I think the original question was simply how the hell to see the output of Rust Hence my explanation that these things are related (i.e. you can try to log from Rust as verbose as you can, but you won't see anything, unless you also increase the logging level in ESP IDF itself). You were also saying: ... but this will not reduce anything in the Rust code. Hence why I had to explain that reduction is Rust is only achievable by using the My comments are as much for the original poster as they are for you and me, so that we can get a complete picture of how logging currently works (as I sometimes feel I'm forgetting details as there are too many). ... and if we can simplify something as the configuration looks a bit complicated yet still not completely flexible. |
Sorry, but I just repeated your setup, and it works for me. Here's my
W.r.t. Rust, fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches();
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default();
log::debug!("Hello, world!");
} ... and NO other changes.
Not necessary. This is the default anyway
Not necessary.
This is the only necessary thing. UPDATE: But the correct name is
Are you building in release or debug? Though it should not matter... |
Related: esp-rs/esp-idf-svc#458 |
Where is the best place to set the logging level at compile time with this project template? Running
RUST_LOG="debug" cargo run
does not print debug logs, I’m guessing because the variable is not passed to the ESP’s runtime environment.The best solution would appear to be setting the log crate’s feature flag as follows, however I’d like to set a different logging level for each profile, and per-profile rustflags are currently unstable.
The text was updated successfully, but these errors were encountered: