simple_logger

Structured Logging with JSON Output for Eiffel

Foundation Layer v1.0.0 MIT

Overview

simple_logger provides an enhanced logging facade for Eiffel with structured fields, JSON output format, child loggers with inherited context, and built-in timing/tracing support. It wraps EiffelStudio's logging facilities with a clean, modern API.

Quick Start

Installation

<library name="simple_logger" location="$SIMPLE_EIFFEL/simple_logger/simple_logger.ecf"/>

Basic Usage

local
    log: SIMPLE_LOGGER
do
    create log.make
    
    -- Basic logging
    log.info ("Application started")
    log.warn ("Low disk space")
    log.error ("Connection failed")
    
    -- With structured fields
    log.with_field ("user", "alice")
    log.with_field ("action", "login")
    log.info ("User logged in")
end

Features

Structured Logging

Key-value fields attached to log entries

JSON Output

Machine-parseable format for log aggregation

Child Loggers

Inherit context fields from parent loggers

Timing Support

Built-in timer for operation duration logging

JSON Output

log.set_json_output (True)
log.info ("Server started")

-- Output:
-- {"timestamp":"2025-12-06T14:30:00Z","level":"info","message":"Server started"}

Child Loggers

-- Create child with inherited context
child := log.child_with_field ("module", "auth")
child.info ("Processing request")
-- Includes: module=auth plus any parent fields

Duration Logging

log.start_timer
-- ... expensive operation ...
log.log_duration ("Operation completed")

API Reference

Log Levels

LevelFeatureUse Case
DEBUGdebug_msgVerbose debugging info
INFOinfoNormal operational messages
WARNwarnWarning conditions
ERRORerrorError conditions
FATALfatalSystem failure

make

create log.make

Create logger with default INFO level and console output.

Ensure

level_is_info: level = Level_info
outputs_to_console: is_console_output

with_field (a_key, a_value: STRING)

log.with_field ("user", "alice")

Add field to next log entry. Returns self for chaining.

child_with_field (a_key, a_value: STRING): SIMPLE_LOGGER

child := log.child_with_field ("module", "auth")

Create child logger with inherited context plus new field.

Configuration

FeatureDescription
set_level (level)Set minimum log level
set_json_output (bool)Enable/disable JSON format
set_file_output (path)Log to file

Timing

FeatureDescription
start_timerStart timing
log_duration (msg)Log elapsed time
enter (feature_name)Log entry with indent
exit (feature_name)Log exit with dedent