pub struct LoggerManager { /* private fields */ }Expand description
Non-blocking JSON logger with daily rotation and automatic old-file cleanup.
§Behaviour
- Log files are named
{YYYY-MM-DD}_{app_name}.jsonland written underlog_path. - A background task cleans files older than
retention_daysonce per day. - Logging is non-blocking: entries use a buffered channel (
try_send). If the buffer (4 096 entries) is full the entry is silently discarded. - Uncaught panics are captured via
std::panic::set_hookand written as"PANIC"entries before the process unwinds.
§Example
use ghpascon_rust::utils::logger_manager::{LoggerManager, LogLevel};
#[tokio::main]
async fn main() {
let logger = LoggerManager::builder("myapp")
.level(LogLevel::Warn)
.log_path("var/log")
.retention_days(30)
.build()
.await;
logger.warn("high memory usage");
logger.error("connection refused");
}Implementations§
Source§impl LoggerManager
impl LoggerManager
Sourcepub fn builder(app_name: impl Into<String>) -> LoggerManagerBuilder
pub fn builder(app_name: impl Into<String>) -> LoggerManagerBuilder
Returns a builder for constructing a LoggerManager.
§Example
use ghpascon_rust::utils::logger_manager::{LoggerManager, LogLevel};
#[tokio::main]
async fn main() {
let logger = LoggerManager::builder("myapp")
.level(LogLevel::Debug)
.build()
.await;
}Sourcepub fn log(&self, level: LogLevel, message: impl Into<String>)
pub fn log(&self, level: LogLevel, message: impl Into<String>)
Emits a log entry at the given level. Non-blocking.
Use the lgr_*! macros for module/file metadata.
pub fn debug(&self, msg: impl Into<String>)
pub fn info(&self, msg: impl Into<String>)
pub fn warn(&self, msg: impl Into<String>)
pub fn error(&self, msg: impl Into<String>)
Trait Implementations§
Source§impl Drop for LoggerManager
impl Drop for LoggerManager
Auto Trait Implementations§
impl !Freeze for LoggerManager
impl RefUnwindSafe for LoggerManager
impl Send for LoggerManager
impl Sync for LoggerManager
impl Unpin for LoggerManager
impl UnsafeUnpin for LoggerManager
impl UnwindSafe for LoggerManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more