Expand description
§FStdout Logger
A flexible logger implementation for Rust that logs to both stdout and a file, with support for colored console output and customizable formatting.
§Key Features
- Log to both stdout and a file simultaneously
- Colored terminal output (configurable)
- Minimal stdout formatting (timestamp without date by default)
- Full file logging with timestamps and source location
- Multiple configuration options and presets
§Basic Usage
use fstdout_logger::init_logger;
use log::info;
// Initialize with defaults (Info level, colors enabled, file info shown)
init_logger(Some("application.log")).expect("Failed to initialize logger");
info!("Application started");
§Configuration Options
The logger can be customized using the LoggerConfig
struct:
use fstdout_logger::{init_logger_with_config, LoggerConfig};
use log::LevelFilter;
// Create a custom configuration
let config = LoggerConfig::builder()
.level(LevelFilter::Debug)
.show_file_info(false) // Don't show file paths in stdout
.show_date_in_stdout(false) // Show only time, not date in stdout
.use_colors(true) // Use colored output in terminal
.build();
init_logger_with_config(Some("debug.log"), config).expect("Failed to initialize logger");
§Presets
The library provides convenient presets for common scenarios:
// For development (Debug level, file info shown)
fstdout_logger::init_development_logger(Some("dev.log")).expect("Failed to initialize logger");
// For production (Info level, no file info)
fstdout_logger::init_production_logger(Some("app.log")).expect("Failed to initialize logger");
Re-exports§
pub use formatter::LogFormatter;
Modules§
Structs§
- FStdout
Logger - The main logger implementation that outputs to stdout and optionally to a file.
- Logger
Config - Configuration for the logger.
- Logger
Config Builder - Builder for constructing a
LoggerConfig
using a fluent API.
Enums§
- LogError
- Errors that can occur when using the logger.
Functions§
- init_
development_ logger - Initialize a development logger (with file info, colored output).
- init_
logger - Initialize a logger with default configuration.
- init_
logger_ with_ config - Initialize a logger with custom configuration.
- init_
logger_ with_ level - Initialize a logger with a specific log level.
- init_
production_ logger - Initialize a production-ready logger (no file info, concise format).
- init_
simple_ stdout_ logger - Initialize a minimal stdout-only logger with just the specified level.
- init_
stdout_ logger - Initialize a logger that only writes to stdout (not to a file).