5 releases

0.1.4 Nov 20, 2024
0.1.3 Nov 20, 2024
0.1.2 Oct 16, 2024
0.1.1 Oct 15, 2024
0.1.0 Oct 15, 2024

#1041 in Concurrency

Download history 29/week @ 2024-11-13 282/week @ 2024-11-20 65/week @ 2024-11-27 107/week @ 2024-12-04 50/week @ 2024-12-11 16/week @ 2024-12-18 8/week @ 2024-12-25 9/week @ 2025-01-08 53/week @ 2025-01-15 5/week @ 2025-01-29 5/week @ 2025-02-05 6/week @ 2025-02-12 19/week @ 2025-02-19 22/week @ 2025-02-26

53 downloads per month
Used in pebblevault

Apache-2.0

8KB
96 lines

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:

[dependencies]
ez_logging = { git = "https://github.com/yourusername/ez_logging.git" }

Or, if you're using it as a local dependency:

[dependencies]
ez_logging = { path = "../ez_logging" }

Usage

  1. Add the following to the root of your main.rs or lib.rs:
#[macro_use]
extern crate ez_logging;
  1. Initialize the logging system at the start of your program:
fn main() {
    ez_logging::init();
    
    // Your code here
}
  1. Use println! as you normally would. It will now log to both console and file:
println!("This is a log message");
println!("You can use {} too", "formatting");
  1. Log messages will appear in both the console and a file named server.log in your project directory.

Example

#[macro_use]
extern crate ez_logging;

fn main() {
    ez_logging::init();
    
    println!("Starting application");
    
    for i in 1..=5 {
        println!("Processing item {}", i);
    }
    
    println!("Application finished");
}

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.

Dependencies

~1–6.5MB
~38K SLoC