pub struct FStdoutLogger { /* private fields */ }Expand description
The main logger implementation that outputs to stdout and optionally to a file.
This struct implements the Log trait from the standard log crate,
handling log messages by:
- Writing to stdout with optional colors and formatting
- Writing to a file (if configured) with full details
§Example
use fstdout_logger::{FStdoutLogger, LoggerConfig};
use log::LevelFilter;
// Creating a logger directly (usually done via helper functions)
let logger = FStdoutLogger::with_config(
Some("app.log"),
LoggerConfig::default()
).expect("Failed to create logger");
// Initialize as the global logger
logger.init_with_level(LevelFilter::Info).expect("Failed to initialize logger");Implementations§
Source§impl FStdoutLogger
impl FStdoutLogger
Sourcepub fn new<P: AsRef<Path>>(file_path: Option<P>) -> Result<Self, LogError>
pub fn new<P: AsRef<Path>>(file_path: Option<P>) -> Result<Self, LogError>
Create a new logger with default configuration.
This is a convenience method that uses LoggerConfig::default().
§Arguments
file_path- Optional path to a log file. IfNone, logs will only go to stdout.
§Returns
A new logger instance or an error if the log file couldn’t be opened.
Sourcepub fn with_config<P: AsRef<Path>>(
file_path: Option<P>,
config: LoggerConfig,
) -> Result<Self, LogError>
pub fn with_config<P: AsRef<Path>>( file_path: Option<P>, config: LoggerConfig, ) -> Result<Self, LogError>
Sourcepub fn init(self) -> Result<(), LogError>
pub fn init(self) -> Result<(), LogError>
Initialize the logger with the default configuration.
This sets the maximum log level to Trace to enable all logs,
but actual filtering will happen according to the level setting
in the logger’s configuration.
§Returns
Ok(()) if initialization succeeded, or an error if it failed.
Sourcepub fn init_with_level(self, level: LevelFilter) -> Result<(), LogError>
pub fn init_with_level(self, level: LevelFilter) -> Result<(), LogError>
Trait Implementations§
Source§impl Log for FStdoutLogger
Implementation of the Log trait for FStdoutLogger.
impl Log for FStdoutLogger
Implementation of the Log trait for FStdoutLogger.
This handles:
- Checking if a log message should be processed (with module-level filtering)
- Formatting messages differently for stdout and file
- Writing to both destinations
- Flushing output streams
Auto Trait Implementations§
impl !Freeze for FStdoutLogger
impl RefUnwindSafe for FStdoutLogger
impl Send for FStdoutLogger
impl Sync for FStdoutLogger
impl Unpin for FStdoutLogger
impl UnwindSafe for FStdoutLogger
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