brk_logger
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.
What it provides
- Colored Console Output: Level-based color coding for easy visual parsing
- File Logging: Optional log file output with automatic rotation
- Sensible Defaults: Pre-configured log levels for Bitcoin and dependency crates
- Timestamp Formatting: Human-readable timestamps with system timezone
Key Features
Console Logging
- Color-coded levels: Error (red), Warn (yellow), Info (green), Debug (blue), Trace (cyan)
- Formatted timestamps:
YYYY-MM-DD HH:MM:SSformat with dimmed styling - Clean output: Minimal formatting focused on readability
File Logging
- Optional file output: Writes to specified file path
- Automatic cleanup: Removes existing log file on initialization
- Append mode: New log entries appended to file
- Plain text format: No colors in file output for better compatibility
Dependency Filtering
Pre-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 framework
Usage
Basic Setup (Console Only)
use brk_logger;
// Initialize with console output only
init?;
// Now use standard logging macros
info!;
warn!;
error!;
With File Logging
use Path;
// Initialize with both console and file output
let log_path = new;
init?;
info!;
Environment Variable Control
# Set log level via environment variable
# Override for specific crates
# Run with custom log level
RUST_LOG=trace
Using Color Utilities
The crate re-exports OwoColorize for consistent coloring:
use OwoColorize;
println!;
println!;
println!;
println!;
Log Format
Console Output
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...
File Output
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...
Default Log Levels
The logger uses these default settings:
- Default level:
info- Shows important operational information - Suppressed crates: Dependencies that produce excessive output are set to
off - Override capability: Can be overridden via
RUST_LOGenvironment variable
Common Log Level Settings
# 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
Integration Examples
In BRK CLI
use brk_logger;
use info;
In Custom Applications
use ;
use ;
Performance Considerations
- Minimal overhead: Lightweight wrapper around
env_logger - Lazy evaluation: Log messages only formatted when level is enabled
- File I/O: Asynchronous file writing doesn't block main thread
- Memory usage: No buffering, logs written immediately
Dependencies
env_logger- Core logging implementationowo_colors- Terminal color supportjiff- Modern date/time handling for timestamps
This README was generated by Claude Code