Class | Ohai::Log::Formatter |
In: |
lib/ohai/log/formatter.rb
|
Parent: | Logger::Formatter |
# File lib/ohai/log/formatter.rb, line 27 27: def self.show_time=(show=false) 28: @@show_time = show 29: end
Prints a log message as ’[time] severity: message’ if Ohai::Log::Formatter.show_time == true. Otherwise, doesn‘t print the time.
# File lib/ohai/log/formatter.rb, line 33 33: def call(severity, time, progname, msg) 34: if @@show_time 35: sprintf("[%s] %s: %s\n", time.rfc2822(), severity, msg2str(msg)) 36: else 37: sprintf("%s: %s\n", severity, msg2str(msg)) 38: end 39: end
Converts some argument to a Logger.severity() call to a string. Regular strings pass through like normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets put through "object.inspect"
# File lib/ohai/log/formatter.rb, line 44 44: def msg2str(msg) 45: case msg 46: when ::String 47: msg 48: when ::Exception 49: "#{ msg.message } (#{ msg.class })\n" << 50: (msg.backtrace || []).join("\n") 51: else 52: msg.inspect 53: end 54: end