#logging #log #log-format #format #no-std

no-std l0g

Opinionated l0gging facade meant for the no_std libraries

1 stable release

1.0.0 Mar 21, 2024

#1590 in Embedded development

Download history 1/week @ 2024-07-23 97/week @ 2024-07-30 178/week @ 2024-08-06 267/week @ 2024-08-13 255/week @ 2024-08-20 22/week @ 2024-08-27 1/week @ 2024-09-17 11/week @ 2024-09-24 24/week @ 2024-10-01 9/week @ 2024-10-08 44/week @ 2024-10-15 6/week @ 2024-10-29 10/week @ 2024-11-05

63 downloads per month

MIT license

8KB
135 lines

l0g

Opinionated l0gging facade meant for the no_std libraries that are also sometimes used in a std context.

Overview

Logging facilities differ depending on the environment, especially between no_std and std. This facade allows to delegate the decision which l0gging implementation shall be used to the top-level application.

Any call to l0g::{error,warn,info,debug,trace} turns into a

  • noop when no feature is set
  • log::{error,warn,info,debug,trace} from the log crate when log feature is set
  • defmt::{error,warn,info,debug,trace} from the defmt crate when defmt feature is set

Moreover, proc-macro is provided to generalize over which formatting implementation should be used

#[l0g::format]
struct MyStruct {
    value: u8
}

turns into

#[derive(core::fmt::Debug)]
struct MyStruct {
    value: u8
}

if log feature is used or

#[derive(defmt::Format)]
struct MyStruct {
    value: u8
}

if defmt feature is used.

This allows a {:?} formatting to work, regardless of which logging implementation is chosen.

Usage

In the Cargo.toml of your libraries just say

l0g = "1"

In the no_std top-level application specify the dependency with the defmt feature. For how to make defmt work, take a look into its respective documentation.

l0g = { version = "1", features = ["defmt"] }

In the std top-level application specify the dependency with the log feature. For how to make log work, take a look into its respective documentation.

l0g = { version = "1", features = ["log"] }

Dependencies

~265–780KB
~18K SLoC