lib/timber/config.rb in timber-2.1.0.rc2 vs lib/timber/config.rb in timber-2.1.0.rc3
- old
+ new
@@ -23,26 +23,40 @@
def call(severity, timestamp, progname, msg)
"[Timber] #{String === msg ? msg : msg.inspect}\n"
end
end
+ DEVELOPMENT_NAME = "development".freeze
PRODUCTION_NAME = "production".freeze
STAGING_NAME = "staging".freeze
+ TEST_NAME = "test".freeze
include Singleton
attr_writer :http_body_limit
# @private
def initialize
@http_body_limit = 2000
end
+ # Convenience method for logging debug statements to the debug logger
+ # set in this class.
+ # @private
+ def debug(&block)
+ debug_logger = Config.instance.debug_logger
+ if debug_logger
+ message = yield
+ debug_logger.debug(message)
+ end
+ true
+ end
+
# This is useful for debugging. This Sets a debug_logger to view internal Timber library
# log messages. The default is `nil`. Meaning log to nothing.
#
- # See {#debug_to_file} and {#debug_to_stdout} for convenience methods that handle creating
+ # See {#debug_to_file!} and {#debug_to_stdout!} for convenience methods that handle creating
# and setting the logger.
#
# @example Rails
# config.timber.debug_logger = ::Logger.new(STDOUT)
# @example Everything else
@@ -57,14 +71,14 @@
end
# A convenience method for writing internal Timber debug messages to a file.
#
# @example Rails
- # config.timber.debug_to_file("#{Rails.root}/log/timber.log")
+ # 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_file(file_path)
+ # Timber::Config.instance.debug_to_file!("log/timber.log")
+ def debug_to_file!(file_path)
unless File.exist? File.dirname path
FileUtils.mkdir_p File.dirname path
end
file = File.open file_path, "a"
file.binmode
@@ -75,14 +89,14 @@
end
# A convenience method for writing internal Timber debug messages to STDOUT.
#
# @example Rails
- # config.timber.debug_to_stdout
+ # config.timber.debug_to_stdout!
# @example Everything else
- # Timber::Config.instance.debug_to_stdout
- def debug_to_stdout
+ # Timber::Config.instance.debug_to_stdout!
+ def debug_to_stdout!
stdout_logger = ::Logger.new(STDOUT)
stdout_logger.formatter = SimpleLogFormatter.new
self.debug_logger = stdout_logger
end
@@ -199,9 +213,19 @@
if @logger.is_a?(Proc)
@logger.call()
else
@logger ||= Logger.new(STDOUT)
end
+ end
+
+ # @private
+ def development?
+ environment == DEVELOPMENT_NAME
+ end
+
+ # @private
+ def test?
+ environment == TEST_NAME
end
# @private
def production?
environment == PRODUCTION_NAME
\ No newline at end of file