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: log_file_path("makit.log"),
          format: :json,
          append: true,
          include_metadata: true,
        },
        # Debug log file in text format
        {
          file: log_file_path("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



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/makit/logging.rb', line 528

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



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/makit/logging.rb', line 553

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



493
494
495
# File 'lib/makit/logging.rb', line 493

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

.default_loggerLogger

Get the default logger instance

Returns:

  • (Logger)

    the default logger



574
575
576
# File 'lib/makit/logging.rb', line 574

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



475
476
477
# File 'lib/makit/logging.rb', line 475

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



502
503
504
# File 'lib/makit/logging.rb', line 502

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



457
458
459
# File 'lib/makit/logging.rb', line 457

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

.log_file_path(filename) ⇒ String

Get the log file path in the user’s temp directory

For log files that would normally be in the project’s artifacts/ directory, this method returns the path in the user’s temp directory (~/.makit/log/) instead. This prevents log files from cluttering project directories.

Parameters:

  • filename (String)

    The log filename (e.g., “makit.log”, “debug.log”)

Returns:

  • (String)

    Full path to the log file in the temp directory



98
99
100
101
# File 'lib/makit/logging.rb', line 98

def self.log_file_path(filename)
  require_relative "directories" unless defined?(Makit::Directories)
  File.join(Makit::Directories::LOG, filename)
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)


116
117
118
119
120
121
122
123
124
# File 'lib/makit/logging.rb', line 116

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



520
521
522
# File 'lib/makit/logging.rb', line 520

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



466
467
468
# File 'lib/makit/logging.rb', line 466

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



511
512
513
# File 'lib/makit/logging.rb', line 511

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)



106
107
108
# File 'lib/makit/logging.rb', line 106

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



484
485
486
# File 'lib/makit/logging.rb', line 484

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