Skip to main content

Crate brk_logger

Crate brk_logger 

Source
Expand description

§brk_logger

Tracing setup: colorized console output with local timestamps, plus optional daily log files.

With a directory, init also writes YYYY-MM-DD.txt (combined) and YYYY-MM-DD_<level>.txt files into it. Each level admits at most 100 writes per second, so a chatty level cannot starve the others; the combined file gets exactly the admitted writes. On startup, log files modified more than seven days ago are removed.

Default filters turn off bitcoin, corepc, tracing, aide, fjall, lsm_tree and tower_http, and limit rmcp to warnings. register_hook installs the process’s single hook, which receives every event the filter admits.

The last 1,000 lines stay in memory: recent returns them, or those after a given line. Each line has a seq counting the process’s lines from 0, so a reader asking again gets each line once, and a jump in seq shows lines that left memory before it asked.

§Environment variables

  • LOG - log level (default: info in release, debug in dev). Example: LOG=debug bitviewd
  • RUST_LOG - comma-separated target=level directives with an optional default level; replaces LOG and every default filter

§Usage

ⓘ
use std::path::Path;

use tracing::info;

fn main() -> std::io::Result<()> {
    brk_logger::init(Some(Path::new("logs")))?; // `None`: console only
    info!("Ready");
    Ok(())
}

Structs§

Line
One logged line.
Recent
The last lines logged, oldest first.

Constants§

LEVEL_NAMES
Level names, as file suffixes and in log lines.

Functions§

init
Initialize the global tracing subscriber with a colorized console layer.
init_with_default_level
Initialize the logger with a caller-selected fallback level.
log_file_date
The day of a file this writer produces, YYYY-MM-DD.txt (combined) or YYYY-MM-DD_<level>.txt: Some("YYYY-MM-DD"), None for any other name.
recent
The kept lines from from (a seq) on, or all of them; lines that left memory meanwhile are skipped, as the jump in seq shows.
register_hook
Registers the process’s single hook, which receives every event the filter admits; errors if one is already registered.
started
When this process began its log.