Skip to main content

log_easy/
lib.rs

1//! Easy-to-use file logger that writes messages in **log-easy-style**.
2//!
3//! ## Format
4//! Each entry is written as:
5//!
6//! ```text
7//! [YYYY-MM-DD HH:MM:SS][LOG_LEVEL] Message
8//! ```
9//!
10//! ## Example
11//! ```rust,no_run
12//! use log_easy::{Logger, LogLevel};
13//!
14//! let logger = Logger::new("app.log").with_level(LogLevel::Info);
15//! logger.info("Application started");
16//! logger.error("An error occurred");
17//! ```
18//!
19//! ## Global macros
20//! ```rust,no_run
21//! use log_easy::{error, info, init_with, Logger, LogLevel};
22//!
23//! init_with(Logger::new("app.log").with_level(LogLevel::Info)).unwrap();
24//! info!("Application started");
25//! error!("An error occurred");
26//! ```
27//!
28//! ## Error handling
29//! The convenience methods (`info`, `warn`, etc.) are **non-intrusive** and never return errors.
30//! If a write fails, the logger prints a message to stderr.
31//!
32//! If you need to handle errors explicitly, use the `try_*` methods (e.g. `try_info`).
33
34mod logger;
35#[macro_use]
36mod macros;
37
38pub use logger::{LogLevel, Logger, init, init_with};
39
40/// Used by macros to access the global logger
41#[doc(hidden)]
42pub fn global_logger() -> Option<&'static Logger> {
43    logger::global()
44}