class Log
Note to self - use log4r next time ;)
Note to self - use log4r next time ;)
Constants
- SYSLOG_OPTS
Public Class Methods
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
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
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
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
# File lib/ec2/amitools/util.rb, line 389 def Log.exception_str(e) e.message + "\n" + e.backtrace.to_s end
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
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 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 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 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 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 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
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
# 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
@deprecated use write
# File lib/ec2/amitools/util.rb, line 349 def Log.xen_msg(msg) write(Verbosity::V4.to_priority) {msg} end
@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
# 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
@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
# 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
@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
# 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
# File lib/ec2/amitools/util.rb, line 451 def Log.time Time.new.to_s end