Crate fstdout_logger

Source
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§

examples
formatter
Log message formatting functionality.

Structs§

FStdoutLogger
The main logger implementation that outputs to stdout and optionally to a file.
LoggerConfig
Configuration for the logger.
LoggerConfigBuilder
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).