Skip to main content Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. Rust
  4. pw_kernel
  5. log_if
  6. log_if

log_if

Macro log_if 

Source
macro_rules! log_if {
    ($condition:expr, $log_level:expr, $format_string:literal $(,)?) => { ... };
    ($condition:expr, $log_level:expr, $format_string:literal, $($args:expr),* $(,)?) => { ... };
}
Expand description

Emit a log message using core::fmt format string semantics if condition is true.

log_if takes an expr condition, a LogLevel, a core::fmt style format string, and necessary arguments to that string and emits a log message to the logging backend.

use pw_log::LogLevel;
use log_if::log_if;

const LOG_FACTS: bool = true;
log_if!(LOG_FACTS, LogLevel::Info, "Log fact: A {} log has a Janka hardness of {} lbf.",
    "Spruce Pine" as &str, 700 as i32);