lib/timber/config.rb in timber-2.0.20 vs lib/timber/config.rb in timber-2.0.21

- old
+ new

@@ -1,5 +1,6 @@ +require "logger" require "singleton" module Timber # Interface for setting and reading Timber configuration. # @@ -11,10 +12,17 @@ # config = Timber::Config.instance # config.append_metdata = false class Config class NoLoggerError < StandardError; end + class SimpleFormatter < ::Logger::Formatter + # This method is invoked when a log event occurs + def call(severity, timestamp, progname, msg) + "[Timber] #{String === msg ? msg : msg.inspect}\n" + end + end + PRODUCTION_NAME = "production".freeze STAGING_NAME = "staging".freeze include Singleton @@ -52,10 +60,11 @@ end file = File.open file_path, "a" file.binmode file.sync = config.autoflush_log file_logger = ::Logger.new(file) + file_logger.formatter = SimpleFormatter.new self.debug_logger = file_logger end # A convenience method for writing debug messages to a file. # @@ -63,10 +72,11 @@ # config.timber.debug_to_file("#{Rails.root}/log/timber.log") # @example Everything else # Timber::Config.instance.debug_to_file("log/timber.log") def debug_to_stdout stdout_logger = ::Logger.new(STDOUT) + stdout_logger.formatter = SimpleFormatter.new self.debug_logger = stdout_logger end # The environment your app is running in. Defaults to `RACK_ENV` and `RAILS_ENV`. # It should be rare that you have to set this. If the aforementioned env vars are not @@ -131,10 +141,14 @@ # Rails.logger = Timber::Logger.new(STDOUT) # config.timber.logger = Rails.logger # @example Everything else # Timber::Config.instance.logger = Timber::Logger.new(STDOUT) def logger - @logger || Logger.new(STDOUT) + if @logger.is_a?(Proc) + @logger.call() + else + @logger ||= Logger.new(STDOUT) + end end private def production? environment == PRODUCTION_NAME \ No newline at end of file