Expand description
Armature Logging Framework
Provides structured logging for the Armature framework with JSON output by default, and configurable pretty-printing for development.
§Features
- JSON by default: Production-ready structured logging
- Pretty printing: Human-readable output for development
- Environment-controlled: Configure via environment variables
- Zero-cost when disabled: Debug macros compile to no-ops in release
- Runtime configurable: Change format/level at runtime
§Quick Start
use armature_log::{debug, info, warn, error};
// Default: JSON output
info!("Server started on port {}", 8080);
// {"timestamp":"2024-12-20T12:00:00Z","level":"INFO","target":"my_app","message":"Server started on port 8080"}
// With target
debug!(target: "armature::router", "Matching route: {}", "/api/users");§Switching to Pretty Logging
§Option 1: Environment Variable (Recommended)
# Pretty format for development
ARMATURE_LOG_FORMAT=pretty cargo run
# JSON format for production (default)
cargo run
# Compact format
ARMATURE_LOG_FORMAT=compact cargo run§Option 2: Programmatic Configuration
use armature_log::{configure, Format, Level};
// Configure for development
configure()
.format(Format::Pretty)
.level(Level::Debug)
.color(true)
.apply();
// Or use presets
armature_log::preset_development(); // Pretty + Debug + Colors
armature_log::preset_production(); // JSON + Info§Environment Variables
| Variable | Values | Default | Description |
|---|---|---|---|
ARMATURE_DEBUG | 1, true | false | Enable debug logging |
ARMATURE_LOG_LEVEL | trace, debug, info, warn, error | info | Minimum log level |
ARMATURE_LOG_FORMAT | json, pretty, compact | json | Output format |
ARMATURE_LOG_COLOR | 1, true, 0, false | auto-detect | Enable ANSI colors |
ARMATURE_LOG_TIMESTAMPS | 1, 0 | 1 | Include timestamps |
ARMATURE_LOG_MODULE | 1, 0 | 1 | Include module path |
§Output Formats
§JSON (Default)
{"timestamp":"2024-12-20T12:00:00Z","level":"INFO","target":"my_app","message":"Server started"}§Pretty
2024-12-20 12:00:00.123 INFO my_app Server started§Compact
12:00:00 I my_app: Server startedMacros§
- debug
- Log a debug message.
- error
- Log an error message.
- info
- Log an info message.
- trace
- Log a trace message.
- warn
- Log a warning message.
Structs§
- Config
Builder - Configuration builder for fluent API.
- LogConfig
- Logging configuration.
Enums§
Functions§
- config
- Get the global configuration.
- configure
- Create a configuration builder.
- current_
format - Get the current log format.
- current_
level - Get current log level.
- init
- Initialize the logging system.
- is_
debug_ enabled - Check if debug logging is enabled.
- is_
level_ enabled - Check if a log level is enabled.
- preset_
development - Apply development preset: Pretty format, Debug level, colors enabled.
- preset_
production - Apply production preset: JSON format, Info level, no colors.
- preset_
quiet - Apply quiet preset: JSON format, Warn level only.
- set_
color - Set whether colors are enabled.
- set_
debug - Enable or disable debug mode at runtime.
- set_
format - Set log format at runtime.
- set_
level - Set log level at runtime.
- set_
module_ path - Set whether module path is included.
- set_
timestamps - Set whether timestamps are included.