forked from ariel-os/ariel-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(log)!: extract the
debug::log
module as a crate
This keeps the `defmt` macros in the `log` module, instead of being exported into `debug` as well.
- Loading branch information
1 parent
6141b3b
commit 56dab71
Showing
7 changed files
with
129 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "ariel-os-log" | ||
version.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
defmt = { workspace = true, optional = true } | ||
|
||
[features] | ||
defmt = ["dep:defmt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//! Provides logging facilities, powered by [`defmt`]. | ||
#![cfg_attr(not(test), no_std)] | ||
#![cfg_attr(test, no_main)] | ||
#![deny(missing_docs)] | ||
#![deny(clippy::pedantic)] | ||
|
||
#[doc(hidden)] | ||
#[cfg(feature = "defmt")] | ||
pub mod log { | ||
//! Provides debug logging, powered by [`defmt`]. | ||
pub use defmt::{Debug2Format, Display2Format}; | ||
|
||
// Required so the macros can access it. | ||
#[doc(hidden)] | ||
pub use defmt; | ||
|
||
// The declarative macros are required because the defmt macros expect defmt to be in scope. | ||
|
||
/// Logs a message at the trace level. | ||
#[macro_export] | ||
macro_rules! trace { | ||
($($arg:tt)*) => {{ | ||
use $crate::log::defmt; | ||
defmt::trace!($($arg)*); | ||
}}; | ||
} | ||
|
||
/// Logs a message at the debug level. | ||
#[macro_export] | ||
macro_rules! debug { | ||
($($arg:tt)*) => {{ | ||
use $crate::log::defmt; | ||
defmt::debug!($($arg)*); | ||
}}; | ||
} | ||
|
||
/// Logs a message at the info level. | ||
#[macro_export] | ||
macro_rules! info { | ||
($($arg:tt)*) => {{ | ||
use $crate::log::defmt; | ||
defmt::info!($($arg)*); | ||
}}; | ||
} | ||
|
||
/// Logs a message at the warn level. | ||
#[macro_export] | ||
macro_rules! warn { | ||
($($arg:tt)*) => {{ | ||
use $crate::log::defmt; | ||
defmt::warn!($($arg)*); | ||
}}; | ||
} | ||
|
||
/// Logs a message at the error level. | ||
#[macro_export] | ||
macro_rules! error { | ||
($($arg:tt)*) => {{ | ||
use $crate::log::defmt; | ||
defmt::error!($($arg)*); | ||
}}; | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
#[cfg(not(feature = "defmt"))] | ||
pub mod log { | ||
//! Stub module for when the `defmt` Cargo feature is not enabled. | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! __stub { | ||
($($arg:tt)*) => {{ | ||
let _ = ($($arg)*); // Do nothing | ||
}}; | ||
} | ||
|
||
pub use __stub as debug; | ||
pub use __stub as error; | ||
pub use __stub as info; | ||
pub use __stub as trace; | ||
pub use __stub as warn; | ||
} | ||
|
||
#[doc(inline)] | ||
pub use log::*; |