Class: AppEngine::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/appengine-apis/logger.rb

Overview

Replacement for the standard logger.rb. Saves logs to the App Engine Dashboard (or to the java logging api when running locally).

logger = AppEngine::Logger.new
logger.warn "foobar"

or (for compatibility with code already using logger.rb)

Logger = AppEngine::Logger
logger = Logger.new(stream)  # stream is ignored
logger.info "Hello, dashboard"

Constant Summary collapse

SEVERITIES =
{
  DEBUG => ApiProxy::LogRecord::Level::debug,
  INFO => ApiProxy::LogRecord::Level::info,
  WARN => ApiProxy::LogRecord::Level::warn,
  ERROR => ApiProxy::LogRecord::Level::error,
  FATAL => ApiProxy::LogRecord::Level::fatal,
}

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Logger

Returns a new instance of Logger.



49
50
51
# File 'lib/appengine-apis/logger.rb', line 49

def initialize(*args)
  super(STDERR)
end

Instance Method Details

#<<(msg) ⇒ Object



53
54
55
# File 'lib/appengine-apis/logger.rb', line 53

def <<(msg)
  write_log(INFO, msg.to_s, "")
end

#add(severity, msg = nil, progname = nil, &block) ⇒ Object Also known as: log



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/appengine-apis/logger.rb', line 57

def add(severity, msg=nil, progname=nil, &block)
  severity ||= UNKNOWN
  return if severity < @level
  progname ||= @progname
  if msg.nil?
    if block_given?
      msg = yield
    else
      msg = progname
      progname = @progname
    end
  end
  write_log(severity, msg, progname)
end