Module: Tom::Log
- Defined in:
- lib/tom/log.rb
Class Method Summary collapse
-
.default_log_level ⇒ Object
::Logger::INFO when in development mode or ENV is set, ::Logger::ERROR otherwise.
-
.init_logger_defaults ⇒ void
Takes the current Log.logger and sets its level to Logger::INFO when you’re in the development mode or when ENV is set.
-
.logger ⇒ Object
Accessor for the current logger.
-
.logger=(logger) ⇒ Object
Allows you to define your own logger.
-
.set_log_level(level) ⇒ Object
Tries to set the level on the logger, if the logger has a method setter.
Class Method Details
.default_log_level ⇒ Object
Returns ::Logger::INFO when in development mode or ENV is set, ::Logger::ERROR otherwise.
45 46 47 48 |
# File 'lib/tom/log.rb', line 45 def self.default_log_level return ::Logger::INFO if Goliath.env == :development || ENV['BOBS'] return ::Logger::ERROR end |
.init_logger_defaults ⇒ void
34 35 36 37 38 39 40 41 |
# File 'lib/tom/log.rb', line 34 def self.init_logger_defaults set_log_level(default_log_level) @logger.datetime_format = "%H:%M:%S:" rescue nil # might not respond_to Logger::Formatter.module_eval( %q{ def call(severity, time, progname, msg)} + %q{ "#{format_datetime(time)} #{msg2str(msg)}\n" end} ) end |
.logger ⇒ Object
Accessor for the current logger
19 20 21 22 23 24 |
# File 'lib/tom/log.rb', line 19 def self.logger return @logger if @logger @logger = ::Logger.new(STDOUT) init_logger_defaults @logger end |
.logger=(logger) ⇒ Object
Allows you to define your own logger. Tom itself will log things as .debug, so you can log with .info level in your app and do stuff. Or you can use your own logging altogether
@return [Object] The logger param
13 14 15 |
# File 'lib/tom/log.rb', line 13 def self.logger=(logger) @logger = logger end |
.set_log_level(level) ⇒ Object
Tries to set the level on the logger, if the logger has a method setter
55 56 57 58 |
# File 'lib/tom/log.rb', line 55 def self.set_log_level(level) return false unless @logger.respond_to?(:level=) @logger.level = level end |