class KXI::Application::Logger

Allows simple unstructured (time-independent) logging

Public Class Methods

new() click to toggle source

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

attach(min = Message::Severity::COMMAND, &block) click to toggle source

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
command(cmd) click to toggle source

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
debug(msg) click to toggle source

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
error(msg) click to toggle source

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
fatal(msg) click to toggle source

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
info(msg) click to toggle source

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
on_message() click to toggle source

Gets the message event @return [KXI::Application::Event] Message event

# File lib/kxi/application/logger.rb, line 9
def on_message
        @event
end
trace(msg) click to toggle source

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
warning(msg) click to toggle source

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

log(severity, msg) click to toggle source
# 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