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

Support for defmt logging #376

Closed
birkenfeld opened this issue Aug 29, 2020 · 4 comments · Fixed by #455
Closed

Support for defmt logging #376

birkenfeld opened this issue Aug 29, 2020 · 4 comments · Fixed by #455

Comments

@birkenfeld
Copy link

https://github.com/knurling-rs/defmt is a new approach to tracing/logging from embedded devices which dramatically reduces bandwidth use by deferring formatting to the host, and using indexed format strings.

I think this is a very good fit for embedded smoltcp, since other than in low-traffic situations it is currently basically impossible to use smoltcp's (extensive) logging. With defmt, this might become feasible.

Unfortunately, format strings are not compatible since for compactness, defmt format strings need to contain more information about the formatted type (e.g. {:u8}).

Since defmt isn't meant for non-embedded use, smoltcp would have to switch between them using a feature flag. The easiest way I could see to support both syntaxes is to use a custom proc macro (net_trace and net_debug are already custom declarative macros anyway), which outputs two versions of the logging call depending on the feature flag selected (and none if logging is switched off). However, it's also conceivable for defmt to implement that, so I opened knurling-rs/defmt#149 there.

cc @thalesfragoso @adamgreig (stm32-eth developers)

@whitequark
Copy link
Contributor

since other than in low-traffic situations it is currently basically impossible to use smoltcp's (extensive) logging

You can write the logs to a ring buffer, and then trigger a snapshot of it through some condition. The utility of this is largely limited to lockups, and while that's nice, I agree with you overall.

However, it's also conceivable for defmt to implement that, so I opened knurling-rs/defmt#149 there.

I would much prefer that to happen. A separate crate that implements just the proc macro would also be fine.

@birkenfeld
Copy link
Author

Thanks for the feedback! In any case, I'll wait for defmt to stabilize enough for a crates.io release before I try to implement anything...

@Dirbaio
Copy link
Member

Dirbaio commented Nov 2, 2020

I have a PoC of this here akiles@f4cc2c9

It's quite ugly, and it required changing all {} to {:?}. It builds for both defmt and log though!

The ideal solution would be some macro that takes a "supercharged" format string and converts it to a defmt format string or a log format string depending on enabled features...

@Dirbaio
Copy link
Member

Dirbaio commented Apr 1, 2021

Done in #455! With defmt 0.2 there's no longer a need to change {} into {:?}, so it was just a matter of wiring it in correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants