Class: Makit::Logging::MultiLogger Deprecated
- Inherits:
-
Object
- Object
- Makit::Logging::MultiLogger
- Defined in:
- lib/makit/logging.rb
Overview
This class is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with multiple middleware instead.
Multi-target logger that writes to multiple destinations
This logger allows writing log messages to multiple targets simultaneously, such as both stdout and a file, or multiple files with different formats.
Class Method Summary collapse
-
.create_file_logger(log_filename, log_level, options) ⇒ Logger
Create a file logger with appropriate formatter.
-
.create_log_filename(options) ⇒ String
Determine the appropriate log filename.
-
.create_logger(options = {}) ⇒ Logger, MultiLogger
deprecated
Deprecated.
This method is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger.new with middleware instead.
Instance Method Summary collapse
-
#<<(message) ⇒ nil
Append a message directly to all logger targets.
-
#add(severity, message = nil, progname = nil, &block) ⇒ nil
Add a message to all logger targets.
-
#close ⇒ nil
Close all logger targets.
-
#initialize(*targets) ⇒ MultiLogger
constructor
Initialize a new MultiLogger with multiple logging targets.
-
#method_missing(method) ⇒ nil
Forward any unknown methods to all logger targets.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if all logger targets respond to a given method.
Constructor Details
#initialize(*targets) ⇒ MultiLogger
Initialize a new MultiLogger with multiple logging targets
238 239 240 241 |
# File 'lib/makit/logging.rb', line 238 def initialize(*targets) warn "Makit::Logging::MultiLogger is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with middleware instead." @targets = targets end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ nil
Forward any unknown methods to all logger targets
This allows calling standard Logger methods like info, debug, error, etc. directly on the MultiLogger instance.
283 284 285 |
# File 'lib/makit/logging.rb', line 283 def method_missing(method, ...) @targets.each { |logger| logger.send(method, ...) } end |
Class Method Details
.create_file_logger(log_filename, log_level, options) ⇒ Logger
Create a file logger with appropriate formatter
Creates a logger that writes to a file with the specified formatter and log level. Ensures the directory for the log file exists.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/makit/logging.rb', line 345 def self.create_file_logger(log_filename, log_level, ) FileUtils.mkdir_p(File.dirname(log_filename)) file_logger = ::Logger.new(log_filename) file_logger.level = log_level # Use structured logging for file output if requested file_logger.formatter = if [:structured_logging] StructuredFormatter.new else PlainFormatter.new end file_logger end |
.create_log_filename(options) ⇒ String
Determine the appropriate log filename
Generates a log filename based on options and the current rake task. If a custom log file is specified in options, that is used. Otherwise, a log file is created in the artifacts directory with a name based on the current rake task.
371 372 373 374 375 376 377 378 379 380 |
# File 'lib/makit/logging.rb', line 371 def self.create_log_filename() if [:log_file] [:log_file] elsif ARGV.empty? "#{Makit::Environment.project_root_directory}/artifacts/rake.log" else task_name = ARGV.join("_").gsub(":", "_") "#{Makit::Environment.project_root_directory}/artifacts/rake_#{task_name}.log" end end |
.create_logger(options = {}) ⇒ Logger, MultiLogger
This method is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger.new with middleware instead.
Create a configured logger based on options
This factory method creates a logger configured with appropriate formatters and targets based on the provided options. By default, it creates a logger that writes to both stdout (with colors) and a log file (plain text).
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/makit/logging.rb', line 311 def self.create_logger( = {}) warn "Makit::Logging::MultiLogger.create_logger is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger.new with middleware instead." log_level = [:level] || DEFAULT_LOG_LEVEL log_level = LOG_LEVELS[log_level] || LOG_LEVELS[DEFAULT_LOG_LEVEL] stdout_logger = ::Logger.new($stdout) stdout_logger.level = log_level stdout_logger.formatter = ColorFormatter.new # if clean or clobber commands are used, then log ONLY to stdout return stdout_logger if ARGV.include?("clean") || ARGV.include?("clobber") return stdout_logger if Makit::Environment.project_root_directory.nil? # Create file logger if logging to file is enabled if [:file_logging] != false log_filename = create_log_filename() file_logger = create_file_logger(log_filename, log_level, ) return MultiLogger.new(file_logger, stdout_logger) end stdout_logger end |
Instance Method Details
#<<(message) ⇒ nil
Append a message directly to all logger targets
261 262 263 264 265 266 |
# File 'lib/makit/logging.rb', line 261 def <<() @targets.each do |logger| logger << logger.flush if logger.respond_to?(:flush) end end |
#add(severity, message = nil, progname = nil, &block) ⇒ nil
Add a message to all logger targets
250 251 252 253 254 255 |
# File 'lib/makit/logging.rb', line 250 def add(severity, = nil, progname = nil, &block) @targets.each do |logger| logger.add(severity, , progname, &block) logger.flush if logger.respond_to?(:flush) end end |
#close ⇒ nil
Close all logger targets
271 272 273 |
# File 'lib/makit/logging.rb', line 271 def close @targets.each(&:close) end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if all logger targets respond to a given method
292 293 294 |
# File 'lib/makit/logging.rb', line 292 def respond_to_missing?(method, include_private = false) @targets.all? { |logger| logger.respond_to?(method, include_private) } end |