-
Notifications
You must be signed in to change notification settings - Fork 10
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
Use defmt or log #295
Use defmt or log #295
Conversation
Thanks for this PR @WilliamTakeshi! For my understanding:
Before merging, I would like to have it tested on an embedded device, like running the no_std example in the nRF52840. |
Yes, RUST_LOG is still supported (I have tested it using the RUST_LOG=error cargo run --bin coapclient
RUST_LOG=trace cargo run --bin coapserver allowing you to see only logs on the server.
By default, neither log nor defmt is enabled. You can enable either one by specifying the desired feature. As for the CI passing, I wasn't aware that we had a test for the log, so it might have been luck that it passed! In addition to specifying one of these features, you could also pass another logger configuration, such as |
I can confirm I successfully tested the native examples with:
That is OK. I am not sure what exactly to test on nrf52840dk. I tried adding As a summary, it would be great if the PR included the changes for the |
@malishav Thanks for testing! Unfortunately, I don't have an embedded device to test this on, making it harder for me to verify the implementation fully. Have you tried adding the features when importing for example:
depending on which embedded device are you using. On a side note, do you guys recommend any cheap device I can use to test it? |
Yes, tried that, without it wouldn't build. It seems using For embedded, our go-to hardware is the nRF52840 chip for now and we are extensively using nRF52840-DK development board. |
Sorry for the late reply! @malishav, thank you for adding examples for the nRF52840! Using these examples, I was able to get
Here is the output I received:
|
Thanks for the update @WilliamTakeshi, the output seems like what it should be, with the Can you add the following to the README before we merge? ## Example: using logs Logs can be used in both native and embedded applications. Once configured in an application, both can be controlled via environment variables: - on native, set `RUST_LOG` to control Rust's built-in `log` facility - on embedded, set `DEFMT_LOG` to control the [defmt](https://github.com/knurling-rs/defmt) crate The selection of `log` or `defmt` is handled internally by the [defmt-or-log](https://github.com/t-moe/defmt-or-log) crate. For example, `examples/lakers-nrf52840` is configured to use `defmt`. To globally enable logs at level `trace`: ```bash DEFMT_LOG=trace cargo run --bin initiator ``` Different log levels can also be set per crate or module. Here's how to globally set logs to level `trace`, while restricting `lakers` to level `info`: ```bash DEFMT_LOG=trace,lakers=info cargo run --bin initiator ``` |
I also couldn't get By the way, should the new paragraph be added to the root |
That would be very welcome! Note that it's already tracked in #298. And yes I think the right place is in the root README. |
This PR addresses issue #280 . It introduces two new optional dependencies:
defmt
anddefmt-or-log
. Additionally, it makes thelog
dependency optional.The purpose of this change is to allow users to specify either
log
ordefmt
as a feature for the lib. This flexibility should simplify debugging the lib on microcontrollers.As this is my first PR for this library, I am open to feedback and suggestions! Please let me know if any changes are needed.