FlashLog
A blazingly fast Rust logging library with lazy evaluation.
Features
- Lazy Evaluation: Most evaluations are performed in the logger thread, resulting in exceptional performance.
- JSON Output: Log messages are printed in
JSONformat for easy parsing and analysis. - LazyString: Provides
LazyStringfor optimized string interpolation. - Customizable: Flexible configuration options for file output, console reporting, buffer size, and more.
- Timezone Support: Ability to set local or custom timezones for log timestamps.
Quick Start
Add FlashLog to your Cargo.toml:
[]
= "0.1"
Basic usage example:
use ;
Advanced Usage
Logging Structs
FlashLog can easily log custom structs:
use ;
use ;
Using LazyString for Optimization
use ;
// The format in the LazyString is evaluated in the logger thread.
// The creation takes around 1.5 ns regardless of the interpolation number
let lazy_msg = new;
log_info!;
Configuration Options
FlashLog offers various configuration options:
let logger = initialize
.with_file? //
.with_console_report
.with_msg_buffer_size
.with_msg_flush_interval
.with_max_log_level
.with_timezone
.launch;
Output Format
Logs are outputted in JSON format for easy parsing:
Benchmark
Test configurations
Print 500,000 logs. Perform the test 5 times. Before each test, sleep for 2 seconds, then print a warm-up message, and then continuously print 500,000 messages. Test has been done on two types: i32 and
message examples for the struct
flashlog: test-file
ftlog: test-file
2024-08-29 09:39:13.503+09 0ms INFO main [src/main.rs:57] Log message: LogStruct { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
fast_log: test-file
2024-08-29 10:31:16.7598955 [INFO] Log message: LogStruct { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
slog: test-file
Aug 29 01:53:20.725 INFO Log message: LogStruct { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
fern: test-file
[2024-08-29T05:59:56.608510100Z INFO example_fern] Log message: LogStruct { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
tracing: test-file
2024-08-30T01:17:18.997070Z INFO example_tracing: Log message: LogStruct { data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
Performance comparisons
Test machine: Ryzen 7 7700, 3.8 Ghz
| Logger | i32 | 80 byte struct |
|---|---|---|
| flashlog | 48 ns | 60 ns |
| ftlog | 260 ns | 480 ns |
| fast_log | 410 ns | 358 ns |
| slog | 250 ns | 452 ns |
| fern | 3,813 ns | 3,962 ns |
| tracing | 4,003 ns | 4,258 ns |
Test machine: i5-14400F, 2.5Ghz
| Logger | i32 | 80 byte struct |
|---|---|---|
| flashlog | 80 ns | 90 ns |
| ftlog | 323 ns | 581 ns |
| fast_log | 500 ns | 500 ns |
| slog | 324 ns | 604 ns |
| fern | 4,732 ns | 5,714 ns |
| tracing | 5,177 ns | 6,190 ns |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Authors
License
This project is licensed under the MIT License - see the LICENSE file for details.