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
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)
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
-
.create_logger(environment: :default) ⇒ Logger
Create a logger with environment-specific configuration.
-
.create_logger_from_file(config_file) ⇒ Logger
Create a logger from configuration file.
-
.current_log_level ⇒ Object
Get the current log level from environment or use default.
-
.current_verbosity ⇒ Object
Get the current verbosity level from environment or use default.
-
.debug(message, context = {}) ⇒ void
Log a debug message.
-
.default_logger ⇒ Logger
Get the default logger instance.
-
.error(message, context = {}) ⇒ void
Log an error message.
-
.fatal(message, context = {}) ⇒ void
Log a fatal message.
-
.info(message, context = {}) ⇒ void
Log an info message.
-
.log_rake_duration ⇒ nil
Logs the duration of a rake task to a file.
-
.quiet(message, context = {}) ⇒ void
Log a quiet message (shown even in quiet mode).
-
.success(message, context = {}) ⇒ void
Log a success message.
-
.verbose(message, context = {}) ⇒ void
Log a verbose message (only shown in verbose or debug mode).
-
.verbosity ⇒ Symbol
Get the current verbosity level from the default logger.
-
.warn(message, context = {}) ⇒ void
Log a warning message.
Class Method Details
.create_logger(environment: :default) ⇒ Logger
Create a logger with environment-specific configuration
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
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_level ⇒ Object
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_verbosity ⇒ Object
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
480 481 482 |
# File 'lib/makit/logging.rb', line 480 def self.debug(, context = {}) DEFAULT_LOGGER.debug(, context) end |
.default_logger ⇒ Logger
Get the default logger instance
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
462 463 464 |
# File 'lib/makit/logging.rb', line 462 def self.error(, context = {}) DEFAULT_LOGGER.error(, context) end |
.fatal(message, context = {}) ⇒ void
This method returns an undefined value.
Log a fatal message
489 490 491 |
# File 'lib/makit/logging.rb', line 489 def self.fatal(, context = {}) DEFAULT_LOGGER.fatal(, context) end |
.info(message, context = {}) ⇒ void
This method returns an undefined value.
Log an info message
444 445 446 |
# File 'lib/makit/logging.rb', line 444 def self.info(, context = {}) DEFAULT_LOGGER.info(, context) end |
.log_rake_duration ⇒ nil
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.
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)
507 508 509 |
# File 'lib/makit/logging.rb', line 507 def self.quiet(, context = {}) DEFAULT_LOGGER.quiet(, context) end |
.success(message, context = {}) ⇒ void
This method returns an undefined value.
Log a success message
453 454 455 |
# File 'lib/makit/logging.rb', line 453 def self.success(, context = {}) DEFAULT_LOGGER.success(, context) end |
.verbose(message, context = {}) ⇒ void
This method returns an undefined value.
Log a verbose message (only shown in verbose or debug mode)
498 499 500 |
# File 'lib/makit/logging.rb', line 498 def self.verbose(, context = {}) DEFAULT_LOGGER.verbose(, context) end |
.verbosity ⇒ Symbol
Get the current verbosity level from the default logger
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
471 472 473 |
# File 'lib/makit/logging.rb', line 471 def self.warn(, context = {}) DEFAULT_LOGGER.warn(, context) end |