sightingdb 0.5.0

A database designed for Sightings, a technique to count items
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::attribute::AttributeView;

/// Emit one line per write, so the log doubles as a record of what was written.
///
/// Statistics are deliberately excluded by the caller: they grow without bound
/// and would dominate every line.
pub fn log_attribute(path: &str, attribute: &AttributeView) {
    // `log::info!` is a no-op when the level is disabled, but serializing is
    // not, so skip that work when nobody is listening.
    if !log::log_enabled!(log::Level::Info) {
        return;
    }

    match serde_json::to_string(attribute) {
        Ok(json) => log::info!("{path} | {json}"),
        Err(e) => log::warn!("{path} | could not serialize attribute: {e}"),
    }
}