Module logger

Module logger 

Source
Expand description

Logging and progress display utilities.

This module provides structured logging for Ralph’s pipeline:

  • Logger struct for consistent, colorized output
  • Progress bar display
  • Section headers and formatting
  • Colors & Formatting for terminal output
  • Test utilities for capturing log output in tests

§Example

use ralph::logger::Logger;
use ralph::logger::Colors;

let colors = Colors::new();
let logger = Logger::new(colors)
    .with_log_file(".agent/logs/pipeline.log");

logger.info("Starting pipeline...");
logger.success("Task completed");
logger.warn("Potential issue detected");
logger.error("Critical failure");

§Testing with TestLogger

For testing purposes, the output module provides TestLogger which implements the same traits as Logger (Printable and std::io::Write) for output capture.

use ralph::logger::output::TestLogger;
use std::io::Write;

let logger = TestLogger::new();
writeln!(logger, "Test message").unwrap();

assert!(logger.has_log("Test message"));
let logs = logger.get_logs();
assert_eq!(logs.len(), 1);

§Trait Implementation

Both Logger and TestLogger implement:

  • Loggable trait - provides unified interface for log output (info, success, warn, error)
  • Printable trait from json_parser::printer - enables terminal detection
  • std::io::Write trait - enables writing to the logger

The Loggable trait mirrors the Printable trait pattern used for printers, providing a consistent API for both production (Logger) and test (TestLogger) scenarios.

Structs§

Colors
ANSI color codes
Logger
Logger for Ralph output.

Constants§

ARROW
Icons for output
BOX_BL
BOX_BR
BOX_H
BOX_TL
Box-drawing characters for visual structure
BOX_TR
BOX_V
CHECK
CROSS
INFO
WARN

Traits§

Loggable
Trait for logger output destinations.

Functions§

argv_requests_json
Detect if command-line arguments request JSON output.
colors_enabled
Check if colors should be enabled
format_generic_json_for_display
Format generic JSON output for display.
print_progress
Print a progress bar with percentage and counts.