class Log

Note to self - use log4r next time ;)

Note to self - use log4r next time ;)

Constants

SYSLOG_OPTS

Public Class Methods

add_stream(stream) click to toggle source

Add an additional stream (like a file, or $stdout) to send log output to.

# File lib/ec2/amitools/util.rb, line 380
def Log.add_stream(stream)
  @@streams_mutex.synchronize do
    @@streams.push(stream)
    @@streams.delete_if { |io| io.closed? }
  end
end
debug(msg=nil) { || ... } click to toggle source

Log a debug message.

# File lib/ec2/amitools/util.rb, line 268
def Log.debug(msg=nil)
  if block_given?
    write(Priority::DEBUG) {yield}
  else
    write(Priority::DEBUG) {msg}
  end
end
err(msg=nil) { || ... } click to toggle source

Log an error message.

# File lib/ec2/amitools/util.rb, line 304
def Log.err(msg=nil)
  if block_given?
    write(Priority::ERR) {yield}
  else
    write(Priority::ERR) {msg}
  end
end
exception(e) { || ... } click to toggle source

Log an unhandled exception. @deprecated use write

# File lib/ec2/amitools/util.rb, line 329
def Log.exception(e)
  if block_given?
    write(Priority::ALERT) {yield}
  else
    write(Priority::ALERT) {Log.exception_str(e)}
  end
end
exception_str(e) click to toggle source
# File lib/ec2/amitools/util.rb, line 389
def Log.exception_str(e)
  e.message + "\n" + e.backtrace.to_s
end
info(msg=nil) { || ... } click to toggle source

Log an informational message.

# File lib/ec2/amitools/util.rb, line 292
def Log.info(msg=nil)
  if block_given?
    write(Priority::INFO) {yield}
  else
    write(Priority::INFO) {msg}
  end
end
msg(msg) click to toggle source

Log an informational message. @deprecated use write

# File lib/ec2/amitools/util.rb, line 342
def Log.msg(msg)
  write(Verbosity::V2.to_priority) {msg}
end
set_facility(facility) click to toggle source

Set the facility to log messages against when no explicit facility is provided.

# File lib/ec2/amitools/util.rb, line 430
def Log.set_facility(facility)
  @@facility = facility
end
set_identity(identity) click to toggle source

Set the identity to log messages against when no explicit identity is provided. If no identity is provided (either using this method or explicitly when logging) the system will use the application name as the identity.

# File lib/ec2/amitools/util.rb, line 441
def Log.set_identity(identity)
  @@identity = identity
end
set_io(io) click to toggle source

Set the IO instance to log to. @deprecated use add_stream

# File lib/ec2/amitools/util.rb, line 260
def Log.set_io(io)
  add_stream(io)
end
set_priority(priority) click to toggle source

Set the minimum priority of the logging. Messages logged with a lower (less urgent) priority will be ignored.

# File lib/ec2/amitools/util.rb, line 420
def Log.set_priority(priority)
  @@priority = priority
end
set_verbosity(verbosity) click to toggle source

Set the verbosity of the logging. @deprecated use set_priority

# File lib/ec2/amitools/util.rb, line 251
def Log.set_verbosity(verbosity)
  set_priority(verbosity.to_priority)
end
warn(msg=nil) { || ... } click to toggle source

Log a warning message.

# File lib/ec2/amitools/util.rb, line 280
def Log.warn(msg=nil)
  if block_given?
    write(Priority::WARNING) {yield}
  else
    write(Priority::WARNING) {msg}
  end
end
write(priority=Priority::DEBUG, facility=nil, identity=nil) { || ... } click to toggle source
# File lib/ec2/amitools/util.rb, line 459
def Log.write(priority=Priority::DEBUG, facility=nil, identity=nil)
  # If the priority of this message is below the defined priority
  # for logging then we don't want to do this at all. NOTE: Priorities
  # for syslog are defined in ascending order (so lower priorities
  # are more urgent).
  return unless priority <= @@priority
  return unless block_given?
  
  begin
    facility = (facility == nil)?(@@facility):(facility)
    fac_int = facility.value
    ident = (identity == nil)?(@@identity):(identity)
    msg = yield
    Syslog.open(ident, SYSLOG_OPTS, fac_int) do |log|
      log.log(priority.value, '%s', msg)
    end

    # Now pass the message onto each registered stream
    # Access to our list of streams is synchronized so that it can be changed
    # at runtime.
    @@streams_mutex.synchronize do
      @@streams.each do |stream|
        begin
          stream.puts "#{time}: #{ident}: #{priority.value}: #{msg}"
          stream.flush
        rescue Exception => e
          $stderr.puts 'error writing to stream [#{stream}], logging to stdout'
        end
      end
    end
  rescue Exception => e
    $stderr.puts "error loggin to syslog, logging to stdout: #{e}"
    if block_given?
      begin
        $stdout.puts "Msg: #{msg}"
      rescue Exception => e
        $stderr.puts "Block raised error: #{e}"
      end
        end
  end
end
xen_msg(msg) click to toggle source

@deprecated use write

# File lib/ec2/amitools/util.rb, line 349
def Log.xen_msg(msg)
  write(Verbosity::V4.to_priority) {msg}
end
xmlrpcfault(xmlrpc_method, fault) click to toggle source

@deprecated use write

# File lib/ec2/amitools/util.rb, line 370
def Log.xmlrpcfault(xmlrpc_method, fault)
  write(Verbosity::V3.to_priority) {Log.xmlrpcfault_str(xmlrpc_method, fault)}
end
xmlrpcfault_str(xmlrpc_method, fault) click to toggle source
# File lib/ec2/amitools/util.rb, line 395
def Log.xmlrpcfault_str(xmlrpc_method, fault)
  "XML-RPC method fault\nmethod: #{xmlrpc_method}\nfault code: #{fault.faultCode}\nfault string: #{fault.faultString}"
end
xmlrpcmethod_call(name, *paramstructs) click to toggle source

@deprecated use write

# File lib/ec2/amitools/util.rb, line 356
def Log.xmlrpcmethod_call(name, *paramstructs)
  write(Verbosity::V3.to_priority) {Log.xmlrpcmethod_call_str(name, paramstructs)}
end
xmlrpcmethod_call_str(name, *paramstructs) click to toggle source
# File lib/ec2/amitools/util.rb, line 401
def Log.xmlrpcmethod_call_str(name, *paramstructs)
  msg = "name: #{name}\n"
  paramstructs.each_index { |i| msg += "parameter #{i + 1}: #{paramstructs[i].inspect}\n" }
  "XML-RPC method call\n#{msg}"
end
xmlrpcmethod_return(name, value) click to toggle source

@deprecated use write

# File lib/ec2/amitools/util.rb, line 363
def Log.xmlrpcmethod_return(name, value)
  write(Verbosity::V3.to_priority) {Log.xmlrpcmethod_return_str(name, value)}
end
xmlrpcmethod_return_str(name, value) click to toggle source
# File lib/ec2/amitools/util.rb, line 409
def Log.xmlrpcmethod_return_str(name, value)
  msg = "name: #{name}\nvalue: #{value.inspect}"
  "XML-RPC method return\n#{msg}"
end

Private Class Methods

time() click to toggle source
# File lib/ec2/amitools/util.rb, line 451
def Log.time
  Time.new.to_s
end