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
225 226 227 228 |
# File 'lib/makit/logging.rb', line 225 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.
270 271 272 |
# File 'lib/makit/logging.rb', line 270 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.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/makit/logging.rb', line 332 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.
358 359 360 361 362 363 364 365 366 367 |
# File 'lib/makit/logging.rb', line 358 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).
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/makit/logging.rb', line 298 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
248 249 250 251 252 253 |
# File 'lib/makit/logging.rb', line 248 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
237 238 239 240 241 242 |
# File 'lib/makit/logging.rb', line 237 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
258 259 260 |
# File 'lib/makit/logging.rb', line 258 def close @targets.each(&:close) end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Check if all logger targets respond to a given method
279 280 281 |
# File 'lib/makit/logging.rb', line 279 def respond_to_missing?(method, include_private = false) @targets.all? { |logger| logger.respond_to?(method, include_private) } end |