log-easy
Easy-to-use file logger that writes messages in a simple, readable format. Built for straightforward file logging with minimal setup.
Installation
[!NOTE] Minimum supported Rust version (MSRV): 1.85
Add this to your Cargo.toml:
[]
= "0.2"
Features
- Log levels: Trace, Debug, Info, Warn, Error
- Global macros for ergonomic logging (
info!,warn!, etc.) - Instance-based API for explicit control
- Minimal dependencies
Log Format
Each entry is written as:
[YYYY-MM-DD HH:MM:SS][LOG_LEVEL] Message
Quick Start (Global Logger + Macros)
use ;
[!NOTE] Global macros require
initorinit_withto be called once before use.
Instance Logger (No Globals)
use ;
Formatting Messages
Macros accept formatting arguments like println!:
use ;
Instance methods accept a preformatted string:
use ;
Log Levels
Messages below the configured level are ignored.
use ;
let logger = new.with_level;
logger.info;
logger.warn;
String Parsing
Log levels can be parsed from strings (case-insensitive). Invalid strings default to LogLevel::Info.
Valid names: trace, debug, info, warn, warning, error
Numeric aliases: 5 = trace, 4 = debug, 3 = info, 2 = warn, 1 = error
use LogLevel;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Example: Parse log level from string
use ;
Initialization (init vs init_with)
init(path)initializes the global logger at the default level (Info).init_with(logger)lets you provide a fully configuredLogger.
use ;
init?;
init_with?;
Both return std::io::Result<()> and will error if the global logger is already initialized.
Error Handling
The convenience methods (info, warn, etc.) are non-intrusive and never return errors.
If a write fails, the logger prints a message to stderr.
If you need to handle errors explicitly, use the try_* methods:
use ;
The try_* macros return std::io::Result<()> as well:
use ;
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.