Class: Cinch::LoggerList

Inherits:
Array
  • Object
show all
Defined in:
lib/cinch/logger_list.rb

Overview

This class allows Cinch to use multiple loggers at once. A common use-case would be to log formatted messages to STDERR and a pisg-compatible log to a file.

It inherits directly from Array, so adding new loggers is as easy as calling LoggerList#push.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LoggerList

Returns a new instance of LoggerList.

Since:

  • 2.0.0



20
21
22
23
# File 'lib/cinch/logger_list.rb', line 20

def initialize(*args)
  @filters = []
  super
end

Instance Attribute Details

#filtersArray<LogFilter>

A list of log filters that will be applied before emitting a log message.

Returns:

Since:

  • 2.3.0



19
20
21
# File 'lib/cinch/logger_list.rb', line 19

def filters
  @filters
end

#level=(level) ⇒ Array<:debug, :log, :info, :warn, :error, :fatal> (writeonly)

Returns The minimum level of events to log.

Returns:

  • (Array<:debug, :log, :info, :warn, :error, :fatal>)

    The minimum level of events to log

Since:

  • 2.0.0



13
14
15
# File 'lib/cinch/logger_list.rb', line 13

def level=(value)
  @level = value
end

Instance Method Details

#debug(message) ⇒ void

This method returns an undefined value.

Logs a debugging message.

Parameters:

Since:

  • 2.0.0

Version:

  • 2.0.0



37
38
39
# File 'lib/cinch/logger_list.rb', line 37

def debug(message)
  (m = filter(message, :debug)) && each { |l| l.debug(m) }
end

#error(message) ⇒ void

This method returns an undefined value.

Logs an error message.

Parameters:

Since:

  • 2.0.0



42
43
44
# File 'lib/cinch/logger_list.rb', line 42

def error(message)
  (m = filter(message, :error)) && each { |l| l.error(m) }
end

#exception(e) ⇒ void

This method returns an undefined value.

Logs an exception.

Parameters:

  • e (Exception)

Since:

  • 2.0.0



72
73
74
# File 'lib/cinch/logger_list.rb', line 72

def exception(e)
  each { |l| l.exception(e) }
end

#fatal(message) ⇒ void

This method returns an undefined value.

Logs an error message.

Parameters:

Since:

  • 2.0.0



47
48
49
# File 'lib/cinch/logger_list.rb', line 47

def fatal(message)
  (m = filter(message, :fatal)) && each { |l| l.fatal(m) }
end

#incoming(message) ⇒ void

This method returns an undefined value.

Logs an incoming IRC message.

Parameters:

Since:

  • 2.0.0



62
63
64
# File 'lib/cinch/logger_list.rb', line 62

def incoming(message)
  (m = filter(message, :incoming)) && each { |l| l.incoming(m) }
end

#info(message) ⇒ void

This method returns an undefined value.

Logs an info message.

Parameters:

Since:

  • 2.0.0



52
53
54
# File 'lib/cinch/logger_list.rb', line 52

def info(message)
  (m = filter(message, :info)) && each { |l| l.info(m) }
end

#log(messages, event = :debug, level = event) ⇒ void

This method returns an undefined value.

Logs a message.

Parameters:

  • messages (String, Array)

    The message(s) to log

  • event (:debug, :incoming, :outgoing, :info, :warn, :exception, :error, :fatal) (defaults to: :debug)

    The kind of event that triggered the message

  • level (:debug, :info, :warn, :error, :fatal) (defaults to: event)

    The level of the message

Since:

  • 2.0.0

Version:

  • 2.0.0



31
32
33
34
# File 'lib/cinch/logger_list.rb', line 31

def log(messages, event = :debug, level = event)
  messages = Array(messages).map { |m| filter(m, event) }.compact
  each { |l| l.log(messages, event, level) }
end

#outgoing(message) ⇒ void

This method returns an undefined value.

Logs an outgoing IRC message.

Parameters:

Since:

  • 2.0.0



67
68
69
# File 'lib/cinch/logger_list.rb', line 67

def outgoing(message)
  (m = filter(message, :outgoing)) && each { |l| l.outgoing(m) }
end

#warn(message) ⇒ void

This method returns an undefined value.

Logs a warning message.

Parameters:

Since:

  • 2.0.0



57
58
59
# File 'lib/cinch/logger_list.rb', line 57

def warn(message)
  (m = filter(message, :warn)) && each { |l| l.warn(m) }
end