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

added option to add support for the log crate #100

Merged
merged 4 commits into from
Aug 10, 2023
Merged

added option to add support for the log crate #100

merged 4 commits into from
Aug 10, 2023

Conversation

MnlPhlp
Copy link
Contributor

@MnlPhlp MnlPhlp commented Jul 20, 2023

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

@@ -69,6 +74,17 @@ fn main() -> ! {
wdt1.disable();
{% endif -%}

{% if logging -%}
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@SergioGasquez SergioGasquez left a 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!

Comment on lines +77 to +80
// 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
Copy link
Member

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?

Copy link
Contributor Author

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

@MnlPhlp
Copy link
Contributor Author

MnlPhlp commented Aug 8, 2023

@SergioGasquez where should this be added in the readme? I currently see no other section that explains any of the code.
I think the comment is enough. If anything this should be an addition to the "understanding esp-template" section in the book.

@SergioGasquez
Copy link
Member

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.

@SergioGasquez SergioGasquez merged commit a2554fb into esp-rs:main Aug 10, 2023
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants