Module: Makit::Logging Deprecated

Defined in:
lib/makit/logging.rb,
lib/makit/logging/logger.rb,
lib/makit/logging/sinks/base.rb,
lib/makit/logging/log_request.rb,
lib/makit/logging/configuration.rb,
lib/makit/logging/sinks/console.rb,
lib/makit/logging/format_registry.rb,
lib/makit/logging/formatters/base.rb,
lib/makit/logging/sinks/file_sink.rb,
lib/makit/logging/sinks/structured.rb,
lib/makit/logging/sinks/unified_file_sink.rb,
lib/makit/logging/formatters/json_formatter.rb,
lib/makit/logging/formatters/text_formatter.rb,
lib/makit/logging/formatters/console_formatter.rb,
lib/makit/logging/formatters/plain_text_formatter.rb

Overview

Deprecated.

The legacy MultiLogger, Formatter classes, and create_logger method are deprecated and will be removed in version 0.2.0. Use the new Logger class with sinks instead.

Logging infrastructure for the Makit gem

This module provides a comprehensive logging system with multiple formatters, multi-target output capabilities, and configurable log levels. It supports:

  • Plain text logging (suitable for files)

  • Colored console output (improved terminal readability)

  • Structured JSON logging (machine-parsable format)

  • Multi-target logging (write to multiple destinations simultaneously)

  • Sink-based output processing (similar to Commands::Runner)

Examples:

Basic usage with new architecture (recommended)

Makit::Logging.info("Application started")
Makit::Logging.success("Build completed")
Makit::Logging.error("Something went wrong")

Custom logger configuration

logger = Makit::Logging::Logger.new(
  sinks: [
    Makit::Logging::Sinks::Console.new,
    Makit::Logging::Sinks::FileSink.new(log_file: "custom.log")
  ]
)
logger.info("Custom message")

Legacy usage (deprecated - will be removed in v0.2.0)

logger = Makit::Logging::MultiLogger.create_logger
logger.info("Application started")
logger.error("Something went wrong")

Defined Under Namespace

Modules: Formatters, Sinks Classes: ColorFormatter, Configuration, FormatRegistry, LogRequest, Logger, MultiLogger, PlainFormatter, StructuredFormatter

Constant Summary collapse

ANSI_COLOR_REGEX =
/\e\[[0-9;]*m/
LOG_LEVELS =

Log levels that can be configured

{
  debug: ::Logger::DEBUG,
  info: ::Logger::INFO,
  warn: ::Logger::WARN,
  error: ::Logger::ERROR,
  fatal: ::Logger::FATAL,
}.freeze
DEFAULT_LOG_LEVEL =

Default log level

:info
DEFAULT_LOGGER =

Default logger with unified file sink This replaces the previous multi-sink approach with a single, configurable sink

Logger.new(
  level: current_log_level,
  verbosity: current_verbosity,
  sinks: [
    Sinks::UnifiedFileSink.new(
      configurations: [
        # Console output with colors and symbols

        {
          file: $stdout,
          format: :console,
          show_timestamp: false,
          show_level: false,
        },
        # Main log file in JSON format

        {
          file: "artifacts/makit.log",
          format: :json,
          append: true,
          include_metadata: true,
        },
        # Debug log file in text format

        {
          file: "artifacts/debug.log",
          format: :text,
          append: true,
          min_level: :debug,
          include_context: true,
        },
      ],
    ),
  ],
)

Class Method Summary collapse

Class Method Details

.create_logger(environment: :default) ⇒ Logger

Create a logger with environment-specific configuration

Parameters:

  • environment (Symbol) (defaults to: :default)

    environment name (:development, :production, :test, :ci)

Returns:

  • (Logger)

    configured logger instance



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/makit/logging.rb', line 515

def self.create_logger(environment: :default)
  config = case environment
    when :development
      Configuration.development_config
    when :production
      Configuration.production_config
    when :test
      Configuration.test_config
    when :ci
      Configuration.ci_config
    else
      Configuration.default_config
    end

  Logger.new(
    sinks: [
      Sinks::UnifiedFileSink.new(configurations: config.configurations),
    ],
  )
end

.create_logger_from_file(config_file) ⇒ Logger

Create a logger from configuration file

Parameters:

  • config_file (String)

    path to configuration file (YAML or JSON)

Returns:

  • (Logger)

    configured logger instance



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/makit/logging.rb', line 540

def self.create_logger_from_file(config_file)
  config = if config_file.end_with?(".yaml") || config_file.end_with?(".yml")
      Configuration.from_yaml(config_file)
    elsif config_file.end_with?(".json")
      Configuration.from_json(config_file)
    else
      raise ArgumentError, "Configuration file must be YAML (.yaml/.yml) or JSON (.json)"
    end

  config.validate!

  Logger.new(
    sinks: [
      Sinks::UnifiedFileSink.new(configurations: config.configurations),
    ],
  )
end

.current_log_levelObject

Get the current log level from environment or use default



75
76
77
78
79
80
# File 'lib/makit/logging.rb', line 75

def self.current_log_level
  env_level = ENV["LOG_LEVEL"]&.downcase&.to_sym
  return env_level if env_level && LOG_LEVELS.key?(env_level)

  DEFAULT_LOG_LEVEL
end

.current_verbosityObject

Get the current verbosity level from environment or use default



83
84
85
86
87
88
# File 'lib/makit/logging.rb', line 83

def self.current_verbosity
  env_verbosity = ENV["VERBOSITY"]&.downcase&.to_sym
  return env_verbosity if env_verbosity && i[quiet normal verbose debug].include?(env_verbosity)

  :normal
end

.debug(message, context = {}) ⇒ void

This method returns an undefined value.

Log a debug message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



480
481
482
# File 'lib/makit/logging.rb', line 480

def self.debug(message, context = {})
  DEFAULT_LOGGER.debug(message, context)
end

.default_loggerLogger

Get the default logger instance

Returns:

  • (Logger)

    the default logger



561
562
563
# File 'lib/makit/logging.rb', line 561

def self.default_logger
  DEFAULT_LOGGER
end

.error(message, context = {}) ⇒ void

This method returns an undefined value.

Log an error message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



462
463
464
# File 'lib/makit/logging.rb', line 462

def self.error(message, context = {})
  DEFAULT_LOGGER.error(message, context)
end

.fatal(message, context = {}) ⇒ void

This method returns an undefined value.

Log a fatal message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



489
490
491
# File 'lib/makit/logging.rb', line 489

def self.fatal(message, context = {})
  DEFAULT_LOGGER.fatal(message, context)
end

.info(message, context = {}) ⇒ void

This method returns an undefined value.

Log an info message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



444
445
446
# File 'lib/makit/logging.rb', line 444

def self.info(message, context = {})
  DEFAULT_LOGGER.info(message, context)
end

.log_rake_durationnil

Logs the duration of a rake task to a file

This method calculates the elapsed time since the STARTTIME constant was set and appends this information to a log file. Used to track performance of rake tasks.

Returns:

  • (nil)


103
104
105
106
107
108
109
110
111
# File 'lib/makit/logging.rb', line 103

def self.log_rake_duration
  # use the STARTTIME constant to log the duration of the rake task

  # to the log/rake.duration.txt file

  duration = Time.now - STARTTIME
  FileUtils.mkdir_p("log")
  File.open("log/rake.duration.txt", "a") do |file|
    file.puts "Rake task duration: #{duration} seconds"
  end
end

.quiet(message, context = {}) ⇒ void

This method returns an undefined value.

Log a quiet message (shown even in quiet mode)

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



507
508
509
# File 'lib/makit/logging.rb', line 507

def self.quiet(message, context = {})
  DEFAULT_LOGGER.quiet(message, context)
end

.success(message, context = {}) ⇒ void

This method returns an undefined value.

Log a success message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



453
454
455
# File 'lib/makit/logging.rb', line 453

def self.success(message, context = {})
  DEFAULT_LOGGER.success(message, context)
end

.verbose(message, context = {}) ⇒ void

This method returns an undefined value.

Log a verbose message (only shown in verbose or debug mode)

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



498
499
500
# File 'lib/makit/logging.rb', line 498

def self.verbose(message, context = {})
  DEFAULT_LOGGER.verbose(message, context)
end

.verbositySymbol

Get the current verbosity level from the default logger

Returns:

  • (Symbol)

    current verbosity level (:quiet, :normal, :verbose, :debug)



93
94
95
# File 'lib/makit/logging.rb', line 93

def self.verbosity
  DEFAULT_LOGGER.verbosity
end

.warn(message, context = {}) ⇒ void

This method returns an undefined value.

Log a warning message

Parameters:

  • message (String)

    the log message

  • context (Hash) (defaults to: {})

    additional context information



471
472
473
# File 'lib/makit/logging.rb', line 471

def self.warn(message, context = {})
  DEFAULT_LOGGER.warn(message, context)
end