Crate armature_log

Crate armature_log 

Source
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

# 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

VariableValuesDefaultDescription
ARMATURE_DEBUG1, truefalseEnable debug logging
ARMATURE_LOG_LEVELtrace, debug, info, warn, errorinfoMinimum log level
ARMATURE_LOG_FORMATjson, pretty, compactjsonOutput format
ARMATURE_LOG_COLOR1, true, 0, falseauto-detectEnable ANSI colors
ARMATURE_LOG_TIMESTAMPS1, 01Include timestamps
ARMATURE_LOG_MODULE1, 01Include 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 started

Macros§

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§

ConfigBuilder
Configuration builder for fluent API.
LogConfig
Logging configuration.

Enums§

Format
Output format for log messages.
Level
Log level for Armature logging.

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.