Class: AC::Logger::Instance

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

Instance Method Summary collapse

Constructor Details

#initialize(out = nil, level = ::Logger::WARN) ⇒ Instance

Returns a new instance of Instance.



33
34
35
36
# File 'lib/ac/logger.rb', line 33

def initialize out = nil, level = ::Logger::WARN
  super(out || default_outstream)
  self.level = level
end

Instance Method Details

#default_outstreamObject

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



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ac/logger.rb', line 21

def default_outstream
  if ! (Object.const_defined? 'Rails')
    STDOUT
  else
    if 'test' === ::Rails.env
      STDOUT
    else 
      "#{::Rails.root.to_s}/log/#{::Rails.env}.log"
    end
  end
end

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

exception convenience function with callstack logging:

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"}"


58
59
60
61
# File 'lib/ac/logger.rb', line 58

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

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

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



39
40
41
# File 'lib/ac/logger.rb', line 39

def format_message(severity, ts, progname, msg)
  "#{ts.strftime '%Y-%m-%d %H:%M:%S'} #{severity.chars.first} #{msg}\n"
end