Module logger

Module logger 

Source
Expand description

Logging infrastructure for vanguards-rs.

This module provides logging functionality using the tracing ecosystem. It supports output to stdout, files, and syslog, with configurable log levels.

§Overview

The logging system provides:

  • Multiple output destinations: stdout, file, or syslog
  • Configurable log levels: From DEBUG to ERROR
  • Python vanguards compatibility: plog function matches Python API
  • Environment variable override: RUST_LOG can override configured level

§Log Levels

From most to least verbose:

LevelDescriptionUse Case
DebugLow-level debuggingDevelopment only
InfoInformational messagesVerbose operation
NoticeNotable eventsDefault level
WarnWarning conditionsPotential issues
ErrorError conditionsFailures

§Example

use vanguards_rs::{LogLevel, logger};

// Initialize logging to stdout at NOTICE level
logger::init(LogLevel::Notice, None).unwrap();

// Log messages using the plog function
logger::plog(LogLevel::Notice, "Vanguards started");
logger::plog(LogLevel::Info, "Connected to Tor");
logger::plog(LogLevel::Warn, "High timeout rate detected");

§Output Destination Examples

use vanguards_rs::{LogLevel, logger};

// Log to stdout (default)
logger::init(LogLevel::Notice, None).unwrap();

// Log to a file
logger::init(LogLevel::Debug, Some("/var/log/vanguards.log")).unwrap();

// Log to syslog
logger::init(LogLevel::Notice, Some(":syslog:")).unwrap();

§What This Module Does NOT Do

  • Log rotation: Use external tools like logrotate
  • Log aggregation: Use external services for centralized logging
  • Structured logging: Currently outputs plain text only

§See Also

Functions§

init
Initialize the logging system.
plog
Log a message at the specified level.