Conversation
0e4ac44 to
ba979b5
Compare
jonas-schievink
left a comment
There was a problem hiding this comment.
Looks generally good, but I'm still not sure what our strategy with log should be. Perhaps the best way forward is to not funnel defmt logs through log and remove that code?
| #[proc_macro] | ||
| #[proc_macro_error] | ||
| pub fn println(args: TokenStream) -> TokenStream { | ||
| function_like::println::expand(args) |
There was a problem hiding this comment.
Is there a reason you couldn't reuse log::expand like the other logging macros? (if so, please add a comment)
There was a problem hiding this comment.
I based it on function write::expand which is simlar, println::expand does not check feature flags and sets a different interned string. But I think both versions could be made work in log::expand.
There was a problem hiding this comment.
Ah, that makes sense. Yeah, would be good to merge the logic together.
| .module_path(module_path) | ||
| .file(file) | ||
| .line(line) | ||
| .build(), |
There was a problem hiding this comment.
Since you don't call .level(...) here, which level will end up in the Record?
There was a problem hiding this comment.
Ah, looks like info: https://docs.rs/log/0.4.14/src/log/lib.rs.html#1157
There was a problem hiding this comment.
The alternative is to be more transparent, for example:
log::logger().log(
&Record::builder()
.args(format_args!("{}", display))
.level(level.unwrap_or(Level::Trace))
.target(&target)
.module_path(module_path)
.file(file)
.line(line)
.build(),
);and remove the if else block completely.
There was a problem hiding this comment.
It's better to be consistent with the underlying default level in log, therefore the call is now .level(level.unwrap_or(Level::Info)
|
This feature still requires a bit of writing in the defmt book so that users know about how & when to use this. |
jonas-schievink
left a comment
There was a problem hiding this comment.
Code LGTM
Still not sure what the best way to proceed with the log interop code is. I'm thinking that deleting it (and handling defmt frames manually) might be the best way forward, otherwise downstream consumers will have println! converted to INFO-level logs, which is kinda wrong.
| crate::Level::Info => Some(Level::Info), | ||
| crate::Level::Warn => Some(Level::Warn), | ||
| crate::Level::Error => Some(Level::Error), | ||
| crate::Level::Println => None, |
There was a problem hiding this comment.
If we keep the fallback to Info, this branch could just be => Level::Info and we'd remove the Option
|
I have not looked at the PR but wanted to comment on these:
I agree with this.
The I think a "stable" |
fb80fec to
2e04bab
Compare
* fix a few lint issues * export `println` macro * add `Tag` variant `Println` * add `expand` function for `println` macro
* rename log level `None` to `Println` * refactor `println` call to use `log::expand` logic * refactor `if else` block to log text
| let timestamp = &target[DEFMT_TARGET_MARKER.len()..]; | ||
|
|
||
| Some(Self { | ||
| (Self{ |
There was a problem hiding this comment.
does this compile? the return type is an option but this no longer has the Some constructor
| ); | ||
| quote_spanned! { | ||
| test.func.sig.ident.span() => defmt::info!(#message, __defmt_test_number, __DEFMT_TEST_COUNT); | ||
| test.func.sig.ident.span() => defmt::println!(#message, __defmt_test_number, __DEFMT_TEST_COUNT); |
| quote!({ | ||
| match (#(&(#formatting_exprs)),*) { | ||
| (#(#patterns),*) => { | ||
| defmt::export::istr(&#format_tag); |
There was a problem hiding this comment.
this should follow the acquire - release pattern used in the log macros, including the header call. the main difference between the two will be that tag used to constructor the header (there's a make_istr call in the expansion I believe)
2e04bab to
049e93c
Compare
This is similar to the `function_like::log::expand` function now.
The `println` macro uses similar logic as the logging macros. When creating a new log frame the log level is optional now, adjusting for the case when a `Frame` is generated from a `println` call.
japaric
left a comment
There was a problem hiding this comment.
Changes look good to me. It's not clear to me, though, what's the output when timestamps are enabled. Could you extend the timestamp snapshot test to include a defmt::println! call?
The other thing that's not obvious from here is whether probe-run will also show the source code location for defmt::println! statements. Including the location would not be standard but certainly useful. I think either way is fine for now personally; same thing for the timestamps.
* refactor `print_location` to take separate arguments instead of a log record
japaric
left a comment
There was a problem hiding this comment.
looks great! feel free to send it to bors with the inline nit addressed 🚀
|
bors r+ |
|
Build succeeded: |
This PR addresses #541, adding a
defmt::println!macro to always log content irrespective of a log level.This changes the
levelproperty inFramestruct to be ofOptiontype, which requires a number of refactorings to handle both ways to log, either using the log macros (e.g.defmt::info!) or using thedefmt::println!macro.The addition of the
defmt::printlnmacro should not break existing functionality.