Skip to main content

Crate rlg_core

Crate rlg_core 

Source
Expand description

§rlg-core — the no_std core of RLG

The pure part of rlg: severity levels, a borrowed Record view, and the rendering of a record into each of the 14 output formats, written through core::fmt::Write. It needs alloc (attributes are a BTreeMap of serde_json values) and nothing from std, so it builds for bare-metal targets such as thumbv7em-none-eabihf.

rlg depends on this crate and re-exports LogLevel and ParseLogLevelError at their old paths; rlg::Log’s Display renders through Record, so the bytes are the same either way. The engine, sinks, config and rlg::LogFormat (whose parsing and validation need std) stay in rlg.

use core::fmt::Write;
use rlg_core::{Format, LogLevel, Record};

let mut out = String::new();
let record = Record::new(LogLevel::WARN, "battery low")
    .component("power")
    .session_id(7)
    .format(Format::Logfmt);
write!(out, "{record}").unwrap();
assert_eq!(
    out,
    "level=warn msg=\"battery low\" session_id=7 component=\"power\""
);

Re-exports§

pub use crate::format::Format;
pub use crate::level::LogLevel;
pub use crate::level::ParseLogLevelError;
pub use crate::record::Attributes;
pub use crate::record::Record;

Modules§

format
The 14 output formats a Record can be written in.
level
Severity levels: ALL through CRITICAL, with FromStr parsing.
record
The borrowed record view and its rendering.