consola-rs π¨
Elegant Console Logger for Rust and Browser (WASM)
A Rust port of unjs/consola providing beautiful, powerful logging for native Rust applications and WebAssembly.
β¨ Features
- π¨ Beautiful Output: Colored, formatted console output with multiple reporters
- π¦ Lightweight: Minimal dependencies, feature-gated integrations
- π¦ Type-Safe: Full Rust type safety with flexible logging API
- π WASM Support: Run in browsers via WebAssembly
- π Throttling: Built-in message deduplication and repetition counting
- βΈοΈ Pause/Resume: Buffer logs and replay them later
- π― Multiple Reporters: Basic, Fancy (with icons), JSON, and custom reporters
- π Ecosystem Integration: Optional
logandtracingcrate support - π¬ Interactive Prompts: Optional interactive CLI prompts (native only)
- π Error Chains: Automatic error source chain formatting
π¦ Installation
Add to your Cargo.toml:
[]
= "0.0.0-alpha.0"
Feature Flags
[]
= { = "0.0.0-alpha.0", = ["color", "fancy", "json"] }
Available features:
color(default) - ANSI color support viaanstreamfancy(default) - Fancy reporter with icons and enhanced formattingjson- JSON reporter for structured loggingprompt-demand- Interactive prompts using thedemandcrate (native only)wasm- WebAssembly support viawasm-bindgenbridge-log- Integration with thelogcratebridge-tracing- Integration with thetracingcrate
π Quick Start
Basic Usage
use ;
With Format Arguments
use ;
let username = "alice";
let count = 42;
info!;
debug!;
Raw Logging (No Formatting)
use info_raw;
// Bypass formatting pipeline for maximum performance
info_raw!;
Custom Log Types
use log_type;
// Register and use custom log types
log_type!;
π Documentation
- Migration Guide - Migrating from JavaScript consola
- Architecture - System design and components
- Custom Reporters - Creating custom reporters
- Prompts - Using interactive prompts (native only)
- Integrations -
logandtracingintegration - Feature Flags - Complete feature matrix
- Benchmarks - Performance characteristics
π WebAssembly Usage
Build for WASM:
# Install wasm-pack
# Build for web target
Use in JavaScript:
import init from './pkg/consola.js';
await ;
;
;
;
Note: Interactive prompts are not available in WASM - calling prompt methods will return an error.
π¨ Reporters
Basic Reporter (Default)
Simple, clean output:
[info] Application started
[warn] Low disk space
[error] Connection failed
Fancy Reporter (with fancy feature)
Enhanced output with icons and colors:
βΉ info Application started
β warn Low disk space
β error Connection failed
JSON Reporter (with json feature)
Structured JSON output for log aggregation:
β‘ Advanced Features
Throttling & Deduplication
Automatically deduplicate repeated messages:
use info;
// These will be coalesced into a single log with repetition count
for _ in 0..100
// Output: [info] Processing batch (x100)
Pause & Resume
Buffer logs and replay them:
// Pause logging
consola.pause;
info!;
warn!;
// Resume and flush all buffered logs
consola.resume;
Error Chain Formatting
Automatically format error source chains:
use error;
use Error;
π§ͺ Testing
# Run all tests
# Run with nextest (recommended)
# Run doctests
π§ Development
# Format code
# Lint
# Build
# Run all checks
π Performance
consola-rs is designed for high performance:
- Zero-cost abstractions: Minimal overhead when logging is disabled
- Optimized hot paths: Raw logging bypasses formatting
- Smart throttling: Efficient deduplication using blake3 hashing
- Small allocations: Uses
smallvecfor common cases
See BENCHMARKS.md for detailed performance characteristics.
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
π License
MIT License - see LICENSE file for details.
π Acknowledgments
- Inspired by unjs/consola
- Built with Rust 2024 edition (MSRV: 1.85)
π Related Projects
- unjs/consola - Original JavaScript implementation
- env_logger - Simple Rust logger
- tracing - Application-level tracing
Status: Alpha - API may change. Not yet recommended for production use.