ez_logging
ez_logging is a simple, easy-to-use logging library for Rust projects. It overrides the standard println! macro to log messages to both the console and a file simultaneously, with automatic timestamping.
Features
- Override
println!to log messages to console and file simultaneously - Automatic timestamping of log messages
- Thread-safe logging
- Easy integration into existing projects without changing print statements
Installation
Add this to your Cargo.toml:
[]
= { = "https://github.com/yourusername/ez_logging.git" }
Or, if you're using it as a local dependency:
[]
= { = "../ez_logging" }
Usage
- Add the following to the root of your main.rs or lib.rs:
extern crate ez_logging;
- Initialize the logging system at the start of your program:
- Use
println!as you normally would. It will now log to both console and file:
println!;
println!;
- Log messages will appear in both the console and a file named
server.login your project directory.
Example
extern crate ez_logging;
Output
Console and server.log:
[2023-05-20 15:30:45] Logging system initialized
[2023-05-20 15:30:45] Starting application
[2023-05-20 15:30:45] Processing item 1
[2023-05-20 15:30:45] Processing item 2
[2023-05-20 15:30:45] Processing item 3
[2023-05-20 15:30:45] Processing item 4
[2023-05-20 15:30:45] Processing item 5
[2023-05-20 15:30:45] Application finished
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.