Crates.io | log-once |
lib.rs | log-once |
version | 0.4.1 |
source | src |
created_at | 2016-11-25 14:10:55.224898 |
updated_at | 2024-01-04 15:13:24.159775 |
description | Collection of helper macros for logging some events only once. |
homepage | https://github.com/Luthaf/log-once |
repository | https://github.com/Luthaf/log-once |
max_upload_size | |
id | 7362 |
size | 29,674 |
Collection of helper macros for logging some events only once.
This crate provide macro in the log_once
family (warn_once!
,
trace_once!
, ...); that only send a logging event once for every message.
It rely and uses the logging infrastructure in the log crate; and
is fully compatible with any logger implementation.
These macro will store the already seen messages in a BTreeSet
, and check
if a message is in the set before sending the log event.
Cargo.toml
file:[dependencies]
log-once = "0.4"
use log_once::{warn_once, log_once};
use log::info;
use log_once::{info_once, warn_once};
pub fn shave_the_yak(yaks: &[Yak]) {
for yak in yaks {
info!(target: "yak_events", "Commencing yak shaving for {yak:?}");
loop {
match find_a_razor() {
Ok(razor) => {
// This will only appear once in the logger output for each razor
info_once!("Razor located: {razor}");
yak.shave(razor);
break;
}
Err(err) => {
// This will only appear once in the logger output for each error
warn_once!("Unable to locate a razor: {err}, retrying");
}
}
}
}
}
log-once is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.