module Tom::Log

Public Class Methods

default_log_level() click to toggle source

@return ::Logger::INFO when in development mode or ENV is set,

::Logger::ERROR otherwise
# 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() click to toggle source

Takes the current {Tom::Log.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) @return [void]

# 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() click to toggle source

Accessor for the current logger @return [Object] See {Tom::Log.logger=}

# 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) click to toggle source

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

@param [Object] logger Some object that implements the

 .info .debug etc.
@return [Object] The logger param
# File lib/tom/log.rb, line 13
def self.logger=(logger)
  @logger = logger
end
set_log_level(level) click to toggle source

Tries to set the level on the logger, if the logger has a method setter

@param The log level you want to set

@return The level you set or false when the logger doesn't have a method setter

# File lib/tom/log.rb, line 55
def self.set_log_level(level)
  return false unless @logger.respond_to?(:level=)
  @logger.level = level
end