Module: Musa::Logger

Included in:
All
Defined in:
lib/musa-dsl/logger/logger.rb

Overview

Logging utilities for Musa DSL.

Provides a specialized logger that integrates with the sequencer to display musical position information alongside standard log messages.

Purpose

When working with sequenced musical compositions, it's crucial to know at what point in musical time events occur. This logger automatically prepends the sequencer's current position (in bars) to each log entry, making debugging and monitoring much more intuitive.

Integration with Sequencer

The logger reads the sequencer's position at the moment each log message is generated. Since positions are typically Rational numbers representing bars (e.g., 4/4 = 1 bar), the formatter renders them with %f after a to_f -- decimal, and not the fraction a Rational usually inspects as.

Common Use Cases

  • Debugging sequencer timing issues
  • Monitoring MIDI output events with their musical timestamps
  • Tracking series evaluation progress
  • Logging voice state changes during playback
  • Performance analysis and timing verification

Examples:

Complete workflow

require 'musa-dsl'

# Setup
sequencer = Musa::Sequencer::Sequencer.new(4, 24)
logger = Musa::Logger::Logger.new(sequencer: sequencer)
logger.level = Logger::INFO

# In your composition
sequencer.at 1 do
  logger.info "Composition started"
end

sequencer.at 4 do
  logger.info "First phrase complete"
end

sequencer.run

# Output on STDERR:
#    1.000: [INFO]  Composition started
#    4.000: [INFO]  First phrase complete

# `at 1` and not `at 0`: bars are numbered from 1 and the sequencer starts
# one tick before bar 1, so an `at 0` block never runs -- silently. And two
# spaces after the level: the progname's slot is empty, not absent.

See Also:

Defined Under Namespace

Classes: Logger