Class: Cinch::Logger::ZcbotLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/cinch/logger/zcbot_logger.rb

Overview

This logger logs all incoming messages in the format of zcbot. All other debug output (outgoing messages, exceptions, …) will silently be dropped. The sole purpose of this logger is to produce logs parseable by pisg (with the zcbot formatter) to create channel statistics..

Instance Method Summary collapse

Constructor Details

#initialize(output = STDERR) ⇒ ZcbotLogger

Returns a new instance of ZcbotLogger.

Parameters:

  • output (IO) (defaults to: STDERR)

    An IO to log to.



11
12
13
14
# File 'lib/cinch/logger/zcbot_logger.rb', line 11

def initialize(output = STDERR)
  @output = output
  @mutex = Mutex.new
end

Instance Method Details

#debug(messages) ⇒ void

This method returns an undefined value.

This method can be used by plugins to log custom messages.

Parameters:

  • message (String)

    The message to log



17
18
# File 'lib/cinch/logger/zcbot_logger.rb', line 17

def debug(messages)
end

#log(messages, kind = :generic) ⇒ void

This method returns an undefined value.

This method is used by #debug and #log_exception to log messages, and also by the IRC parser to log incoming and outgoing messages. You should not have to call this.

Parameters:

  • message (String)

    The message to log

  • kind (Symbol<:debug, :generic, :incoming, :outgoing>) (defaults to: :generic)

    The kind of message to log



21
22
23
24
25
26
27
28
29
30
# File 'lib/cinch/logger/zcbot_logger.rb', line 21

def log(messages, kind = :generic)
  return if kind != :incoming

  @mutex.synchronize do
    messages = [messages].flatten.map {|s| s.to_s.chomp}
    messages.each do |msg|
      @output.puts Time.now.strftime("%m/%d/%Y %H:%M:%S ") + msg.encode("locale", {:invalid => :replace, :undef => :replace})
    end
  end
end

#log_exception(e) ⇒ void

This method returns an undefined value.

This method is used for logging messages.

Parameters:

  • e (Exception)

    The exception to log



33
34
# File 'lib/cinch/logger/zcbot_logger.rb', line 33

def log_exception(e)
end