-
Notifications
You must be signed in to change notification settings - Fork 29
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
added option to add support for the log crate #100
Conversation
@@ -69,6 +74,17 @@ fn main() -> ! { | |||
wdt1.disable(); | |||
{% endif -%} | |||
|
|||
{% if logging -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using init_logger_from_env()
is easier - plus it supports ESP_LOGTARGET
.
Difference is it defaults to Off
not Info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.
This is what i used in my code because i wanted logging in the default mode.
But I think changing it and adding a comment that you have to set ESP_LOGLEVEL to use it should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an idea if there is any way to set the ENV variable somewhere in the cargo config so that cargo run
just works and prints logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly all of that only works for your own crate, not for dependencies (in this case esp_println)
At least i couldn't figure out a way to get log output, but printing ESP_LOGLEVEL from the config in my own code worked.
So it looks like the rustc-env is only applied to your own code and the ENV section only at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it works for dependencies too. Smoltcp does its configuration this way. There is a horrible bug in cargo which means it doesn't detect changes with the [env]
section: rust-lang/cargo#10358, so make sure whenever you add/change/remove the [env]
section do a clean build afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok
Thanks for the information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the contribution!
// setup logger | ||
// To change the log_level change the env section in .config/cargo.toml | ||
// or remove it and set ESP_LOGLEVEL manually before running cargo run | ||
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could move this information to the README instead of having it on code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you ever see the readme if you just use cargo generate to generate a project from the template?
I think it is fine because it's just a template and you will look at the code. But we can also add it to the readme additionally
@SergioGasquez where should this be added in the readme? I currently see no other section that explains any of the code. |
Maybe where we explain the prompt, we could add a hint to the comments in the code or something, but you are right, I think the comment is enough, at least for now, if any complaints about this appear in the future we can address it. |
This just adds another option in the advanced section that adds a dependency to the log crate and initializes the logger from esp_println
Also fixed a broken link to the esp-template section in the book