This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
added option to add support for the log crate #100
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ extern crate alloc; | |
use esp_backtrace as _; | ||
use esp_println::println; | ||
use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc}; | ||
{% if logging -%} | ||
use log::info; | ||
{% endif -%} | ||
|
||
{%- if alloc %} | ||
#[global_allocator] | ||
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); | ||
|
@@ -69,6 +73,15 @@ fn main() -> ! { | |
wdt1.disable(); | ||
{% endif -%} | ||
|
||
{% if logging -%} | ||
// 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 | ||
Comment on lines
+77
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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? |
||
esp_println::logger::init_logger_from_env(); | ||
info!("Logger is setup"); | ||
{% endif -%} | ||
|
||
println!("Hello world!"); | ||
|
||
loop {} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 supportsESP_LOGTARGET
.Difference is it defaults to
Off
notInfo
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.
Yes, see here: https://doc.rust-lang.org/cargo/reference/config.html#configuration-format
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.