Class: BmcDaemonLib::Logger
- Inherits:
-
Logger
- Object
- Logger
- BmcDaemonLib::Logger
- Defined in:
- lib/bmc-daemon-lib/logger.rb
Constant Summary collapse
- DEFAULT_FORMAT =
{ # header: "%s ‡ %d\t%-8s %-12s ", header: "%{time} %7{pid} %-6{severity} %-10{pipe} | %{context}", # header: "%{time} %7{pid} %-6{severity} %-10{pipe}(-‡-)%{context}", time: "%Y-%m-%d %H:%M:%S", context: "[%s]", text: "%s", array: " · %s", hash: " · %-15s : %s", trim: 400, }
Instance Method Summary collapse
-
#add(severity, message, context = nil, details = nil) ⇒ Object
def info message add Logger::INFO, “INFO:#message” end def debug message add Logger::DEBUG, “DEBUG:#message” end def error message add Logger::ERROR, “ERROR:#message” end.
-
#initialize(filename, rotation = nil) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(filename, rotation = nil) ⇒ Logger
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bmc-daemon-lib/logger.rb', line 17 def initialize filename, rotation = nil # Initialize super @format = DEFAULT_FORMAT # Import LOGGER_FORMAT if defined if (defined?'LOGGER_FORMAT') && (LOGGER_FORMAT.is_a? Hash) @format.merge! LOGGER_FORMAT end # Define formatter self.formatter = proc do |severity, datetime, progname, | formatter(severity, datetime, progname, ) end end |
Instance Method Details
#add(severity, message, context = nil, details = nil) ⇒ Object
def info message
add Logger::INFO, "INFO:#{message}"
end def debug message
add Logger::DEBUG, "DEBUG:#{message}"
end def error message
add Logger::ERROR, "ERROR:#{message}"
end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bmc-daemon-lib/logger.rb', line 43 def add severity, , context = nil, details = nil # Start from an empty messages list with the main message = [] << sprintf(@format[:text], ) if # Add raw lines if context.nil? && (details.is_a? Array) = details # Add details from array elsif details.is_a? Array details.each do |line| << sprintf(@format[:array], line) end # Add details from hash elsif details.is_a?(Hash) || details.is_a?(Hashie::Mash) details.each do |key, value| << sprintf(@format[:hash], key, value) end # Add each line of "details" after split elsif details.is_a? String details.lines.each do |line| << line unless line.empty? end end # Pass all that stuff to my parent super severity, , context end |