Class: Gom::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/gom/logger.rb

Constant Summary collapse

Levels =

Gom::Log.level = Gom::Attribute.value(“/gom/log:level”, ::Logger::INFO)

{
  "debug" => ::Logger::DEBUG,
  "info"  => ::Logger::INFO,
  "warn"  => ::Logger::WARN,
  "error" => ::Logger::ERROR,
  "fatal" => ::Logger::FATAL,
}
DEFAULT_OUT =

output defaults to STDOUT for rails test and non-rails apps, to a logfile otherwise

begin
  if (RAILS_ROOT.nil? rescue true)
    STDOUT
  else
    if 'test' === RAILS_ENV
      STDOUT
    else 
      "#{RAILS_ROOT}/log/gom-#{RAILS_ENV}.log"
    end
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(out = DEFAULT_OUT) ⇒ Logger

Returns a new instance of Logger.



32
33
34
# File 'lib/gom/logger.rb', line 32

def initialize out = DEFAULT_OUT
  super out
end

Instance Method Details

#ex(e, msg = nil, level = :error) ⇒ Object

experimental convenience function:

Log.ex e

does actually do:

Log.error e
Log.debug "#{e.backtrace.join "\n\t"}"

and:

Log.ex e, "some message here"

stands for:

Log.error "some message here"
Log.debug "#{e.backtrace.join "\n\t"}"


56
57
58
59
# File 'lib/gom/logger.rb', line 56

def ex e, msg = nil, level = :error
  send level, "#{e}: #{(msg || e)}"
  debug "#{e} -- callstack: #{msg}\n\t#{e.backtrace.join "\n\t"}"
end

#format_message(severity, timestamp, progname, msg) ⇒ Object

this is to de-patch the rails formatting patch..



37
38
39
# File 'lib/gom/logger.rb', line 37

def format_message(severity, timestamp, progname, msg)
  "#{timestamp.strftime '%Y-%m-%d %H:%M:%S'} #{severity[0,1]} #{msg}\n"
end