#defmt #logging #debugging #no-std

no-std defmt-or-log

Logging macros that forward to either defmt or log

4 releases

0.2.1 Jan 16, 2024
0.2.0 Nov 20, 2023
0.1.1 Nov 20, 2023
0.1.0 Nov 20, 2023

#424 in Embedded development

Download history 1/week @ 2024-01-26 70/week @ 2024-02-02 99/week @ 2024-02-09 118/week @ 2024-02-16 175/week @ 2024-02-23 168/week @ 2024-03-01 186/week @ 2024-03-08 154/week @ 2024-03-15 134/week @ 2024-03-22 103/week @ 2024-03-29 132/week @ 2024-04-05 162/week @ 2024-04-12 177/week @ 2024-04-19 215/week @ 2024-04-26 173/week @ 2024-05-03 104/week @ 2024-05-10

718 downloads per month

MIT/Apache

13KB
270 lines

defmt-or-log

In embedded projects you often want to log something either via core::fmt::Debug or defmt::Format, depending on the configuration. The crate defmt-or-log provides the usual logger macros and either forwards them to the log or defmt crate, depending on the enabled features.

Furthermore, the defmt-or-log crate provides:

  • the FormatOrDebug trait, that uses core::fmt::Debug or defmt::Format as super-trait and provides matching blanket implementations. This is useful for specifying trait bounds.
  • the Debug2Format struct, which behaves similar to defmt::Debug2Format, but does nothing extra if using log.
  • the Display2Format struct, which behaves similar to defmt::Display2Format, but does nothing extra if using log.

See examples/derive.rs.

You may either enable the log or the defmt feature but not both.
The feature at_least_one (enabled per default) generates a compiler error if neither log nor defmt are enabled.

This repository, also provides the defmt-or-log-macros crate, that contains Proc Macros to conditonally derive core::fmt::Debug or defmt::Format, depending on the enabled features.

Supported macros (defmt-or-log crate):

  • trace

  • debug

  • info

  • warn

  • error

  • assert

  • assert_eq

  • assert_ne

  • debug_assert

  • debug_assert_eq

  • debug_assert_ne

  • todo

  • unreachable

  • panic

  • unwrap

  • intern

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.3–0.9MB
~20K SLoC