Sha256: fa4a533913ed750cca1606eccb89e27735367c2759d35fd2809bc880dc1ff2a4
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module Nucleus # Logging module for Nucleus. # Include via # include Nucleus::Logging # and then log your messages: # log.info('This is a test log message') # # @author Willem Buys # Idea by Willem 'Jacob' Buys, as seen on http://stackoverflow.com/questions/917566/ruby-share-logger-instance-among-module-classes module Logging def log @log ||= Logging.logger_for(self.class.name) end # Use a hash class-ivar to cache a unique Logger per class: @loggers = {} class << self def logger_for(classname) @loggers[classname] ||= configure_logger_for(classname) end def configure_logger_for(classname) # prepare logging dir log_dir = nucleus_config.logging.path log_file = File.join(log_dir, 'nucleus.log') # prepare path and create missing directories FileUtils.mkdir_p(log_dir) unless File.directory?(log_dir) # create the loggers std_log = Logger.new(STDOUT) # use rotation for x days file_log = Logger.new(log_file, 'daily', 7) # include custom log format that includes the request id formatter = Nucleus::Logging::Formatter.new [file_log, std_log].each do |logger| # apply format logger.formatter = formatter # apply the classname logger.progname = classname end # apply the log level from the app. configuration multi_logger = MultiLogger.new( level: nucleus_config.logging.key?(:level) ? nucleus_config.logging.level : Logger::Severity::WARN, loggers: [std_log, file_log]) multi_logger end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nucleus-0.3.1 | lib/nucleus/core/common/logging/logging.rb |
nucleus-0.2.0 | lib/nucleus/core/common/logging/logging.rb |
nucleus-0.1.0 | lib/nucleus/core/common/logging/logging.rb |