96 releases (53 stable)
Uses new Rust 2024
new 1.10.8 | Mar 30, 2025 |
---|---|
1.1.30 | Feb 26, 2025 |
0.29.5 | Jan 13, 2025 |
0.5.0 | Dec 31, 2024 |
#1718 in Network programming
3,456 downloads per month
Used in 5 crates
(3 directly)
17KB
301 lines
hyperlane-log
A Rust logging library that supports both asynchronous and synchronous logging. It provides multiple log levels, such as error, info, and debug. Users can define custom log handling methods and configure log file paths. The library supports log rotation, automatically creating a new log file when the current file reaches the specified size limit. It allows flexible logging configurations, making it suitable for both high-performance asynchronous applications and traditional synchronous logging scenarios. The asynchronous mode utilizes Tokio's async channels for efficient log buffering, while the synchronous mode writes logs directly to the file system.
Installation
To use this crate, you can run cmd:
cargo add hyperlane-log
Log Storage Location Description
Three directories will be created under the user-specified directory: one for error logs, one for info logs, and one for debug logs. Each of these directories will contain a subdirectory named by the date, and the log files within these subdirectories will be named in the format
timestamp.index.log
.
Use sync
use hyperlane_log::*;
let log: Log = Log::new("./logs", 1_024_000);
log.error("error data!", |error| {
let write_data: String = format!("User error func => {:?}\n", error);
write_data
});
log.info("info data!", |info| {
let write_data: String = format!("User info func => {:?}\n", info);
write_data
});
log.debug("debug data!", |debug| {
let write_data: String = format!("User debug func => {:#?}\n", debug);
write_data
});
Use async
use hyperlane_log::*;
let log: Log = Log::new("./logs", 1_024_000);
log.async_error("async error data!", |error| {
let write_data: String = format!("User error func => {:?}\n", error);
write_data
});
log.async_info("async info data!", |info| {
let write_data: String = format!("User info func => {:?}\n", info);
write_data
});
log.async_debug("async debug data!", |debug| {
let write_data: String = format!("User debug func => {:#?}\n", debug);
write_data
});
Disable log
let log: Log = Log::new("./logs", DISABLE_LOG_FILE_SIZE);
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Contact
For any inquiries, please reach out to the author at ltpp-universe root@ltpp.vip.
Dependencies
~2.6–8.5MB
~74K SLoC