Class: Cinch::Logger

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

Overview

This is the base logger class from which all loggers have to inherit.

Version:

  • 2.0.0

Direct Known Subclasses

FormattedLogger, ZcbotLogger

Defined Under Namespace

Classes: FormattedLogger, ZcbotLogger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Logger

Returns a new instance of Logger.

Parameters:

  • output (IO)

    The I/O object to write log data to



23
24
25
26
27
# File 'lib/cinch/logger.rb', line 23

def initialize(output)
  @output = output
  @mutex  = Mutex.new
  @level  = :debug
end

Instance Attribute Details

#levelArray<:debug, :log, :info, :warn, :error, :fatal>

Returns The minimum level of events to log.

Returns:

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

    The minimum level of events to log



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

def level
  @level
end

#mutexMutex (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Mutex)


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

def mutex
  @mutex
end

#outputIO (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (IO)


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

def output
  @output
end

Instance Method Details

#debug(message)

This method returns an undefined value.

Logs a debugging message.

Parameters:

Version:

  • 2.0.0



34
35
36
# File 'lib/cinch/logger.rb', line 34

def debug(message)
  log(message, :debug)
end

#error(message)

This method returns an undefined value.

Logs an error message.

Parameters:

Since:

  • 2.0.0



43
44
45
# File 'lib/cinch/logger.rb', line 43

def error(message)
  log(message, :error)
end

#exception(e)

This method returns an undefined value.

Logs an exception.

Parameters:

  • e (Exception)

Since:

  • 2.0.0



97
98
99
# File 'lib/cinch/logger.rb', line 97

def exception(e)
  log(e.message, :exception, :error)
end

#fatal(message)

This method returns an undefined value.

Logs a fatal message.

Parameters:

Since:

  • 2.0.0



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

def fatal(message)
  log(message, :fatal)
end

#incoming(message)

This method returns an undefined value.

Logs an incoming IRC message.

Parameters:

Since:

  • 2.0.0



79
80
81
# File 'lib/cinch/logger.rb', line 79

def incoming(message)
  log(message, :incoming, :log)
end

#info(message)

This method returns an undefined value.

Logs an info message.

Parameters:

Since:

  • 2.0.0



61
62
63
# File 'lib/cinch/logger.rb', line 61

def info(message)
  log(message, :info)
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

Version:

  • 2.0.0



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cinch/logger.rb', line 110

def log(messages, event = :debug, level = event)
  return unless will_log?(level)
  @mutex.synchronize do
    Array(messages).each do |message|
      message = format_general(message)
      message = format_message(message, event)

      next if message.nil?
      @output.puts message.encode("locale", {:invalid => :replace, :undef => :replace})
    end
  end
end

#outgoing(message)

This method returns an undefined value.

Logs an outgoing IRC message.

Parameters:

Since:

  • 2.0.0



88
89
90
# File 'lib/cinch/logger.rb', line 88

def outgoing(message)
  log(message, :outgoing, :log)
end

#warn(message)

This method returns an undefined value.

Logs a warning message.

Parameters:

Since:

  • 2.0.0



70
71
72
# File 'lib/cinch/logger.rb', line 70

def warn(message)
  log(message, :warn)
end

#will_log?(level) ⇒ Boolean

Returns Whether the currently set logging level will allow the passed in level to be logged.

Parameters:

  • level (:debug, :info, :warn, :error, :fatal)

Returns:

  • (Boolean)

    Whether the currently set logging level will allow the passed in level to be logged

Since:

  • 2.0.0



127
128
129
# File 'lib/cinch/logger.rb', line 127

def will_log?(level)
  LevelOrder.index(level) >= LevelOrder.index(@level)
end