class KXI::Application::Logger
Allows simple unstructured (time-independent) logging
Public Class Methods
Instantiates the {KXI::Application::Logger} class
# File lib/kxi/application/logger.rb, line 23 def initialize @event = KXI::Application::Event.new @start = DateTime.now end
Public Instance Methods
Attaches action to message event @param min [KXI::Application::Logger::Message::Severity] Minimal severity of message @yield [msg] Event
action @yieldparam msg [KXI::Application::Logger::Message] Logger
message @return [Number] Id of event hook
# File lib/kxi/application/logger.rb, line 18 def attach(min = Message::Severity::COMMAND, &block) return @event.add { |s, msg| block.call(msg) if msg.severity.level >= min.level } end
Logs message with the {KXI::Application::Logger::Message::Severity::COMMAND} severity @param cmd [String] Executed command
# File lib/kxi/application/logger.rb, line 30 def command(cmd) log(Message::Severity::COMMAND, cmd) end
Logs message with the {KXI::Application::Logger::Message::Severity::DEBUG} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 42 def debug(msg) log(Message::Severity::DEBUG, msg) end
Logs message with the {KXI::Application::Logger::Message::Severity::ERROR} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 60 def error(msg) log(Message::Severity::ERROR, msg) end
Logs message with the {KXI::Application::Logger::Message::Severity::FATAL} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 66 def fatal(msg) log(Message::Severity::FATAL, msg) end
Logs message with the {KXI::Application::Logger::Message::Severity::INFO} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 48 def info(msg) log(Message::Severity::INFO, msg) end
Gets the message event @return [KXI::Application::Event] Message
event
# File lib/kxi/application/logger.rb, line 9 def on_message @event end
Logs message with the {KXI::Application::Logger::Message::Severity::TRACE} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 36 def trace(msg) log(Message::Severity::TRACE, msg) end
Logs message with the {KXI::Application::Logger::Message::Severity::WARNING} severity @param msg [String] Text of message
# File lib/kxi/application/logger.rb, line 54 def warning(msg) log(Message::Severity::WARNING, msg) end
Private Instance Methods
# File lib/kxi/application/logger.rb, line 70 def log(severity, msg) now = DateTime.now @event.fire(self, Message.new(severity, now - @start, now, msg)) end