Module: Tom::Log

Defined in:
lib/tom/log.rb

Class Method Summary collapse

Class Method Details

.default_log_levelObject

Returns ::Logger::INFO when in development mode or ENV is set, ::Logger::ERROR otherwise.

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_defaultsvoid

This method returns an undefined value.

Takes the current logger and sets its level to Logger::INFO when you’re in the development mode or when ENV is set. Otherwise the log level is set to Logger::ERROR.

Also, the log format is changed to something short (hh:mm:ss)



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

.loggerObject

Accessor for the current logger

Returns:



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

Parameters:

  • logger (Object)

    Some object that implements the .info .debug etc.



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

Parameters:

  • The

    log level you want to set

Returns:

  • The level you set or false when the logger doesn’t have 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