FStdout Logger
A simple and flexible dual-destination logger for Rust applications that implements the log crate's API.
Features
- Log messages to both stdout and a file simultaneously
- Configurable log levels (Trace, Debug, Info, Warn, Error)
- Colored output for stdout (with different colors for each log level)
- Plain text output for log files (no color codes)
- Compact timestamps in stdout (only time, HH:MM:SS)
- Complete timestamps in log files (includes date)
- Optional file and line number information
- Highly configurable via simple builder API
- Compatible with the standard
logcrate macros
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.4"
The crate uses the following dependencies internally:
coloredfor terminal coloringchronofor timestamp formattingthiserrorfor error handling
Usage
Simple Usage
use init_logger;
use ;
Using Presets
For common use cases, presets are available:
use ;
use ;
Custom Configuration
For full control, use the configuration builder:
use ;
use ;
Output Format
Terminal Output (Default)
By default, terminal output shows a concise format with colors:
[HH:MM:SS LEVEL file:line] Message
For example:
[14:23:45 INFO main.rs:25] Application started
Log messages are colored according to log level:
ERROR: Bold RedWARN: Bold YellowINFO: Bold BlueDEBUG: GreenTRACE: Default terminal color
The timestamp and file information are displayed in a dimmed color to make the log level and message stand out.
File Output (Always Plain Text)
Log messages in files always include the date and file information:
[YYYY-MM-DD HH:MM:SS LEVEL file:line] Message
For example:
[2023-05-15 14:23:45 INFO main.rs:25] Application started
Configuration Options
You can configure the output format through the LoggerConfig:
show_file_info- Toggle display of file and line informationshow_date_in_stdout- Toggle inclusion of date in terminal outputuse_colors- Enable or disable colored output in terminallevel- Set the minimum log level to display
Run Examples
The crate includes examples that demonstrate its usage:
# Simple logging with custom configuration
# Stdout-only logging with minimal format
# Comparing different color and format options
# Demonstrating production vs development presets
Full API
The logger provides several initialization functions for different use cases:
init_logger(path)- Simple initialization with defaultsinit_logger_with_level(path, level)- Set a specific log levelinit_logger_with_config(path, config)- Use a custom configurationinit_production_logger(path)- Use production-optimized settingsinit_development_logger(path)- Use development-optimized settingsinit_stdout_logger(config)- Initialize a stdout-only loggerinit_simple_stdout_logger(level)- Initialize a minimal stdout-only logger
License
This project is licensed under the MIT License - see the LICENSE file for details.