Class: Cakewalk::LoggerList

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

Overview

This class allows Cakewalk 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



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

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



17
18
19
# File 'lib/cakewalk/logger_list.rb', line 17

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



11
12
13
# File 'lib/cakewalk/logger_list.rb', line 11

def level=(value)
  @level = value
end

Instance Method Details

#debug(message)

This method returns an undefined value.

Logs a debugging message.

Parameters:

Since:

  • 2.0.0

Version:

  • 2.0.0



35
36
37
# File 'lib/cakewalk/logger_list.rb', line 35

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

#error(message)

This method returns an undefined value.

Logs an error message.

Parameters:

Since:

  • 2.0.0



40
41
42
# File 'lib/cakewalk/logger_list.rb', line 40

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

#exception(e)

This method returns an undefined value.

Logs an exception.

Parameters:

  • e (Exception)

Since:

  • 2.0.0



70
71
72
# File 'lib/cakewalk/logger_list.rb', line 70

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

#fatal(message)

This method returns an undefined value.

Logs an error message.

Parameters:

Since:

  • 2.0.0



45
46
47
# File 'lib/cakewalk/logger_list.rb', line 45

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

#incoming(message)

This method returns an undefined value.

Logs an incoming IRC message.

Parameters:

Since:

  • 2.0.0



60
61
62
# File 'lib/cakewalk/logger_list.rb', line 60

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

#info(message)

This method returns an undefined value.

Logs an info message.

Parameters:

Since:

  • 2.0.0



50
51
52
# File 'lib/cakewalk/logger_list.rb', line 50

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

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

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



29
30
31
32
# File 'lib/cakewalk/logger_list.rb', line 29

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)

This method returns an undefined value.

Logs an outgoing IRC message.

Parameters:

Since:

  • 2.0.0



65
66
67
# File 'lib/cakewalk/logger_list.rb', line 65

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

#warn(message)

This method returns an undefined value.

Logs a warning message.

Parameters:

Since:

  • 2.0.0



55
56
57
# File 'lib/cakewalk/logger_list.rb', line 55

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