Class: Cinch::Logger
- Inherits:
-
Object
- Object
- Cinch::Logger
- 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.
Direct Known Subclasses
Defined Under Namespace
Classes: FormattedLogger, ZcbotLogger
Instance Attribute Summary collapse
-
#level ⇒ Array<:debug, :log, :info, :warn, :error, :fatal>
The minimum level of events to log.
-
#mutex ⇒ Mutex
readonly
private
-
#output ⇒ IO
readonly
private
Instance Method Summary collapse
-
#debug(message)
Logs a debugging message.
-
#error(message)
Logs an error message.
-
#exception(e)
Logs an exception.
-
#fatal(message)
Logs a fatal message.
-
#incoming(message)
Logs an incoming IRC message.
-
#info(message)
Logs an info message.
-
#initialize(output) ⇒ Logger
constructor
A new instance of Logger.
-
#log(messages, event = :debug, level = event)
Logs a message.
-
#outgoing(message)
Logs an outgoing IRC message.
-
#warn(message)
Logs a warning message.
-
#will_log?(level) ⇒ Boolean
Whether the currently set logging level will allow the passed in level to be logged.
Constructor Details
#initialize(output) ⇒ Logger
Returns a new instance of Logger.
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
#level ⇒ Array<:debug, :log, :info, :warn, :error, :fatal>
Returns The minimum level of events to log.
12 13 14 |
# File 'lib/cinch/logger.rb', line 12 def level @level end |
#mutex ⇒ Mutex (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.
16 17 18 |
# File 'lib/cinch/logger.rb', line 16 def mutex @mutex end |
#output ⇒ IO (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.
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.
34 35 36 |
# File 'lib/cinch/logger.rb', line 34 def debug() log(, :debug) end |
#error(message)
This method returns an undefined value.
Logs an error message.
43 44 45 |
# File 'lib/cinch/logger.rb', line 43 def error() log(, :error) end |
#exception(e)
This method returns an undefined value.
Logs an exception.
97 98 99 |
# File 'lib/cinch/logger.rb', line 97 def exception(e) log(e., :exception, :error) end |
#fatal(message)
This method returns an undefined value.
Logs a fatal message.
52 53 54 |
# File 'lib/cinch/logger.rb', line 52 def fatal() log(, :fatal) end |
#incoming(message)
This method returns an undefined value.
Logs an incoming IRC message.
79 80 81 |
# File 'lib/cinch/logger.rb', line 79 def incoming() log(, :incoming, :log) end |
#info(message)
This method returns an undefined value.
Logs an info message.
61 62 63 |
# File 'lib/cinch/logger.rb', line 61 def info() log(, :info) end |
#log(messages, event = :debug, level = event)
This method returns an undefined value.
Logs a message.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cinch/logger.rb', line 110 def log(, event = :debug, level = event) return unless will_log?(level) @mutex.synchronize do Array().each do || = format_general() = (, event) next if .nil? @output.puts .encode("locale", {:invalid => :replace, :undef => :replace}) end end end |
#outgoing(message)
This method returns an undefined value.
Logs an outgoing IRC message.
88 89 90 |
# File 'lib/cinch/logger.rb', line 88 def outgoing() log(, :outgoing, :log) end |
#warn(message)
This method returns an undefined value.
Logs a warning message.
70 71 72 |
# File 'lib/cinch/logger.rb', line 70 def warn() log(, :warn) end |
#will_log?(level) ⇒ Boolean
Returns Whether the currently set logging level will allow the passed in level to be logged.
127 128 129 |
# File 'lib/cinch/logger.rb', line 127 def will_log?(level) LevelOrder.index(level) >= LevelOrder.index(@level) end |