| Crates.io | brk_logger |
| lib.rs | brk_logger |
| version | 0.0.109 |
| created_at | 2025-02-23 23:29:09.312366+00 |
| updated_at | 2025-09-20 17:20:59.294666+00 |
| description | A thin wrapper around env_logger |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1566724 |
| size | 23,071 |
Colored console logging with optional file output for Bitcoin Research Kit applications.
This crate provides a thin wrapper around env_logger with enhanced formatting, colored output, and optional file logging. Designed specifically for BRK applications, it offers structured logging with timestamps, level-based coloring, and automatic filtering of noisy dependencies.
Key Features:
RUST_LOGTarget Use Cases:
cargo add brk_logger
use brk_logger;
// Initialize with console output only
brk_logger::init(None)?;
// Initialize with file logging
let log_path = std::path::Path::new("application.log");
brk_logger::init(Some(log_path))?;
// Use standard log macros
log::info!("Application started");
log::warn!("Configuration issue detected");
log::error!("Failed to process block");
init(path: Option<&Path>) -> io::Result<()>
Initializes the logging system with optional file output. Console logging is always enabled with color formatting.
Re-exported Types:
OwoColorize: Color formatting trait for custom colored outputConsole Output Format:
2024-09-16 14:23:45 - INFO Application started successfully
2024-09-16 14:23:46 - WARN Bitcoin RPC connection slow
2024-09-16 14:23:47 - ERROR Failed to parse block data
File Output Format (Plain Text):
2024-09-16 14:23:45 - info Application started successfully
2024-09-16 14:23:46 - warn Bitcoin RPC connection slow
2024-09-16 14:23:47 - error Failed to parse block data
The logger automatically filters out verbose logs from common dependencies:
bitcoin=off - Bitcoin library internalsbitcoincore-rpc=off - RPC client detailsfjall=off - Database engine logslsm_tree=off - LSM tree operationstracing=off - Tracing framework internalsuse brk_logger;
use log::{info, warn, error};
fn main() -> std::io::Result<()> {
// Initialize logging to console only
brk_logger::init(None)?;
info!("Starting Bitcoin analysis");
warn!("Price feed temporarily unavailable");
error!("Block parsing failed at height 750000");
Ok(())
}
use brk_logger;
use std::path::Path;
fn main() -> std::io::Result<()> {
let log_file = Path::new("/var/log/brk/application.log");
// Initialize with dual output: console + file
brk_logger::init(Some(log_file))?;
log::info!("Application configured with file logging");
// Both console (colored) and file (plain) will receive this log
log::error!("Critical system error occurred");
Ok(())
}
# Set custom log level and targets
export RUST_LOG="debug,brk_indexer=trace,bitcoin=warn"
# Run application - logger respects RUST_LOG
./my_brk_app
use brk_logger;
fn main() -> std::io::Result<()> {
// Respects RUST_LOG environment variable
brk_logger::init(None)?;
log::debug!("Debug information (only shown if RUST_LOG=debug)");
log::trace!("Trace information (only for specific modules)");
Ok(())
}
use brk_logger::OwoColorize;
fn print_status() {
println!("Status: {}", "Connected".green());
println!("Height: {}", "800000".bright_blue());
println!("Error: {}", "Connection failed".red());
}
init() configures env_logger with custom formatterRUST_LOG or uses default filter configurationDefault filter prioritizes BRK application logs while suppressing:
Main Function: init() function that configures env_logger with custom formatting and dual output
Dependencies: Built on env_logger for filtering, jiff for timestamps, owo-colors for terminal colors
Output Streams: Simultaneous console (colored) and file (plain text) logging with different formatting
Timestamp Format: System timezone-aware formatting using %Y-%m-%d %H:%M:%S pattern
Color Implementation: Level-based color mapping with owo-colors for terminal output
Filter Configuration: Predefined filter string that suppresses verbose dependencies while enabling BRK logs
Architecture: Thin wrapper pattern that enhances env_logger with BRK-specific formatting and behavior
This README was generated by Claude Code