FlashLog
A blazingly fast Rust logging library with lazy evaluation.
Important Changes in Version 0.3.0
-
Cloning in New Macros: In
flash_xxx_ct!macros, cloning happens automatically inside the macro. Users don't need to clone data outside the macro, but be aware that implicit cloning still occurs in the worker thread. -
Timestamp Generation: Timestamps are now generated in the logger thread rather than the worker thread.
-
Compile-Time Feature Options: New compile-time feature options have been added, compatible with the
flash_xxx_ct!macros. Theflash_xxx!macros are now deprecated in favor of the new compile-time filtered macros.
Features
- Lazy Evaluation: Most evaluations are performed in the logger thread, resulting in exceptional performance.
- Lazy String: String interpolation in
flash_xxx!macros is inherently lazy. - JSON Output: Log messages are printed in
JSONformat for easy parsing and analysis. - 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.3", = ["max-level-info"]}
The compile time feature max-level-info is optional and can be omitted. It sets the maximum log level to Info at compile time.
flash_xxx_ct! macros are filtered only by the compile-time feature not using the runtime configuration.
Available compile-time features are:
max-level-offmax-level-errormax-level-warnmax-level-infomax-level-debugmax-level-trace
Basic usage example:
use ;
Advanced Usage
Getting the Log File Path
Since FlashLog appends a timestamp to the file name, you can retrieve the actual file path using get_initial_log_file_path().
Note: This returns only the initial log file path, not the current file after rolling. This design avoids synchronization overhead to maintain performance.
use ;
Logging Structs
FlashLog can easily log custom structs:
use ;
use ;
Configuration and Log Interfaces
Topic and message are optional and separated by a semicolon. In addition, messages can be added with key-value pairs
use ;
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 | 30 ns | 40 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 | 64 ns | 89 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.