Crates.io | brk_logger |
lib.rs | brk_logger |
version | 0.0.95 |
created_at | 2025-02-23 23:29:09.312366+00 |
updated_at | 2025-08-28 10:44:36.843302+00 |
description | A thin wrapper around env_logger |
homepage | https://bitcoinresearchkit.org |
repository | https://github.com/bitcoinresearchkit/brk |
max_upload_size | |
id | 1566724 |
size | 21,692 |
Logging utilities with colored console output and file logging
brk_logger
provides a thin wrapper around env_logger
with BRK-specific defaults, colored console output, and optional file logging. It's designed to provide clear, readable logs for Bitcoin data processing operations.
YYYY-MM-DD HH:MM:SS
format with dimmed stylingPre-configured to suppress noisy logs from common dependencies:
bitcoin=off
- Bitcoin protocol librarybitcoincore-rpc=off
- RPC clientfjall=off
- Key-value storelsm_tree=off
- LSM tree implementationrolldown=off
- Bundlertracing=off
- Tracing frameworkuse brk_logger;
// Initialize with console output only
brk_logger::init(None)?;
// Now use standard logging macros
log::info!("BRK starting up");
log::warn!("Bitcoin Core not fully synced");
log::error!("Failed to connect to RPC");
use std::path::Path;
// Initialize with both console and file output
let log_path = Path::new("~/.brk/brk.log");
brk_logger::init(Some(log_path))?;
log::info!("Logs will appear in console and file");
# Set log level via environment variable
export RUST_LOG=debug
export RUST_LOG=info,brk_parser=debug # Override for specific crates
# Run with custom log level
RUST_LOG=trace brk
The crate re-exports OwoColorize
for consistent coloring:
use brk_logger::OwoColorize;
println!("Success: {}", "Operation completed".green());
println!("Warning: {}", "Low disk space".yellow());
println!("Error: {}", "Connection failed".red());
println!("Info: {}", "Processing block 800000".bright_black());
2024-12-25 10:30:15 - info Starting BRK indexer
2024-12-25 10:30:16 - warn Bitcoin Core still syncing (99.8% complete)
2024-12-25 10:30:45 - info Indexed block 900000 (1.2M transactions)
2024-12-25 10:30:46 - error Connection to RPC failed, retrying...
2024-12-25 10:30:15 - info Starting BRK indexer
2024-12-25 10:30:16 - warn Bitcoin Core still syncing (99.8% complete)
2024-12-25 10:30:45 - info Indexed block 900000 (1.2M transactions)
2024-12-25 10:30:46 - error Connection to RPC failed, retrying...
The logger uses these default settings:
info
- Shows important operational informationoff
RUST_LOG
environment variable# Minimal output (errors and warnings only)
RUST_LOG=warn
# Standard output (recommended)
RUST_LOG=info
# Verbose output (for debugging)
RUST_LOG=debug
# Maximum output (for development)
RUST_LOG=trace
# Mixed levels (info by default, debug for specific crates)
RUST_LOG=info,brk_indexer=debug,brk_computer=trace
use brk_logger;
use log::info;
fn main() -> Result<()> {
// Initialize logging early in main
brk_logger::init(Some(Path::new("~/.brk/brk.log")))?;
info!("BRK CLI starting");
// ... rest of application
Ok(())
}
use brk_logger::{self, OwoColorize};
use log::{info, warn, error};
fn setup_logging() -> std::io::Result<()> {
// Console only for development
brk_logger::init(None)?;
info!("Application initialized");
Ok(())
}
fn process_data() {
info!("Processing Bitcoin data...");
// Use color utilities for progress
println!("Progress: {}", "50%".green());
warn!("Large memory usage detected");
error!("Critical error: {}", "Database connection lost".red());
}
env_logger
env_logger
- Core logging implementationowo_colors
- Terminal color supportjiff
- Modern date/time handling for timestampsThis README was generated by Claude Code