-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
decoder logging: add parameter to indicate defmt awareness #724
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR. It does look good to me, but it is unclear when we want the next breaking change of |
I am just wondering if it wouldn't be easier to just always set the log-level if it is |
that could shave off a few lines - in that case I'd probably remove the |
I am unsure if this is possible, since we use |
If we don't change the public api, then we could also merge this sooner, since it wouldn't be a breaking change anymore. |
ok, probably not a good idea then. I didn't try it out either though 🙃
hm. any idea how to achieve that? |
I guess I could introduce a new function for defmt-aware logging instead of adding a parameter to the existing one. New functions aren't actually breaking, even if they change an API surface, no? |
I am unsure. If someone did But if we just always pass the log level I think we don't need to make any change to the API |
@spookyvision There is another breaking release for |
I think following code would allow to use both a defmt-aware logger and a normal one, without the need to add a new argument. let mut builder = Record::builder();
// set Level, useful for non-defmt loggers
// defmt-aware loggers should use the level from the Payload
if let Some(level) = level {
builder.level(level);
}
let target = format!(
"{}{}",
DEFMT_TARGET_MARKER,
serde_json::to_value(Payload { timestamp, level }).unwrap()
);
log::logger().log(
&builder
.args(format_args!("{}", frame.display_message()))
.target(&target)
.module_path(module_path)
.file(file)
.line(line)
.build(),
); |
sometimes it's preferable to use an existing logger instead of a bespoke defmt-aware one. This PR makes it possible to preserve log levels in this case. It breaks a public API so requires a version bump.