CCB Logger
đ A beautiful, terminal-focused structured logger for Rust
CCB brings elegance and visual appeal to the Rust ecosystem. It is designed for command-line interface (CLI) applications that want to achieve beautiful, readable, and structured log output.
Features
- Semantic Log Levels: Trace, Debug, Info, Warn, Error with four-character alignment
- Automatic Colors: Beautiful colored output with smart terminal detection
- Precise Timestamps: High-precision timestamps in
2006-01-02 03:04:05.789format - Chainable Context: Add structured key-value pairs with
with(key, value) - Simple Macros: Easy-to-use macros with variadic arguments support
- Global Logger: Set and use a global logger instance across your application
- Terminal Friendly: No icons, maximum compatibility across terminals
- Zero Config: Works beautifully out of the box with sensible defaults
Quick Start
Add CCB Logger to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
JSON Output Example
use Logger;
Custom Logger Configuration
use ;
JSON Output Configuration
use Logger;
Advanced Usage
use ;
Output Examples
2024-01-15 14:30:25.1234 INFO Application started
2024-01-15 14:30:25.1235 WARN Configuration file not found path=config.toml
2024-01-15 14:30:25.1236 INFO User login user_id=12345 ip=192.168.1.100
2024-01-15 14:30:25.1237 ERRO Database connection failed error=timeout retry_count=3
2024-01-15 14:30:25.1238 DEBG Cache hit key=user:12345 ttl=300
Log Levels
CCB supports five log levels with four-character alignment:
| Level | Code | Color | Description |
|---|---|---|---|
| Trace | TRCE |
Cyan | đ Detailed tracing information |
| Debug | DEBG |
Blue | đ Debug information for developers |
| Info | INFO |
Green | âšī¸ General information messages |
| Warn | WARN |
Yellow | â ī¸ Warning messages |
| Error | ERRO |
Red | â Error conditions |
Configuration Options
Logger Methods
with_level(level)- Set minimum log levelwith_colors(bool)- Enable/disable colored outputwith_timestamp(bool)- Show/hide timestampswith(key, value)- Add context key-value pair
Environment Detection
CCB automatically detects if output is going to a terminal and enables colors accordingly. You can override this behavior:
let logger = new.with_colors; // Force disable colors
Testing
Run the test suite:
Run tests with output:
Examples
Check out the examples/ directory for more usage patterns:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- đ´ Fork the repository
- đ Create your feature branch (
git checkout -b feature/amazing-feature) - â
Commit your changes (
git commit -m 'Add some amazing feature') - đ¤ Push to the branch (
git push origin feature/amazing-feature) - đ Open a Pull Request
TODO
- Add
asynclogging methods andasync-stdintegration - Avoid HashMap cloning, use
Arc<Context>orCow<str>for string allocation optimization - Use
RwLockinstead ofMutexto avoid deadlock risks - Split the 1000+ lines
lib.rsinto multiple modules (levels, formatters, outputs, etc.) - Add JSON Schema support and custom field serialization
- Add file output, rotation, and compression features
- Support complex filtering based on field values and regex patterns
- Add boundary tests, stress tests, and concurrency tests
- Support configuration file and environment variable driven configuration
- Support custom formatters and interceptors
- Output to console, file, and network simultaneously
- Sampling and aggregation for high-frequency logs
- Lightweight mode optimized for production environments
- Automatically add call stack, thread ID, and other fields
- Automatic detection of development/testing/production environments
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by charmbracelet/log â¤ī¸
- CCB has no real meaning, the name was given by a friend
- Built with â¤ī¸ for the Rust community
- Thanks to all contributors! đ
Related Projects
- charmbracelet/log - The original Go implementation
- env_logger - Simple logger controlled via environment
- tracing - Application-level tracing framework