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
Constant Summary collapse
- LEVEL_ORDER =
[:debug, :log, :info, :warn, :error, :fatal]
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) ⇒ void
Logs a debugging message.
-
#error(message) ⇒ void
Logs an error message.
-
#exception(e) ⇒ void
Logs an exception.
-
#fatal(message) ⇒ void
Logs a fatal message.
-
#incoming(message) ⇒ void
Logs an incoming IRC message.
-
#info(message) ⇒ void
Logs an info message.
-
#initialize(output, level: :debug) ⇒ Logger
constructor
A new instance of Logger.
-
#log(messages, event = :debug, level = event) ⇒ void
Logs a message.
-
#outgoing(message) ⇒ void
Logs an outgoing IRC message.
-
#warn(message) ⇒ void
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, level: :debug) ⇒ Logger
Returns a new instance of Logger.
25 26 27 28 29 |
# File 'lib/cinch/logger.rb', line 25 def initialize(output, level: :debug) @output = output @mutex = Mutex.new @level = level end |
Instance Attribute Details
#level ⇒ Array<:debug, :log, :info, :warn, :error, :fatal>
Returns The minimum level of events to log.
14 15 16 |
# File 'lib/cinch/logger.rb', line 14 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.
18 19 20 |
# File 'lib/cinch/logger.rb', line 18 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.
22 23 24 |
# File 'lib/cinch/logger.rb', line 22 def output @output end |
Instance Method Details
#debug(message) ⇒ void
This method returns an undefined value.
Logs a debugging message.
36 37 38 |
# File 'lib/cinch/logger.rb', line 36 def debug() log(, :debug) end |
#error(message) ⇒ void
This method returns an undefined value.
Logs an error message.
45 46 47 |
# File 'lib/cinch/logger.rb', line 45 def error() log(, :error) end |
#exception(e) ⇒ void
This method returns an undefined value.
Logs an exception.
99 100 101 |
# File 'lib/cinch/logger.rb', line 99 def exception(e) log(e., :exception, :error) end |
#fatal(message) ⇒ void
This method returns an undefined value.
Logs a fatal message.
54 55 56 |
# File 'lib/cinch/logger.rb', line 54 def fatal() log(, :fatal) end |
#incoming(message) ⇒ void
This method returns an undefined value.
Logs an incoming IRC message.
81 82 83 |
# File 'lib/cinch/logger.rb', line 81 def incoming() log(, :incoming, :log) end |
#info(message) ⇒ void
This method returns an undefined value.
Logs an info message.
63 64 65 |
# File 'lib/cinch/logger.rb', line 63 def info() log(, :info) end |
#log(messages, event = :debug, level = event) ⇒ void
This method returns an undefined value.
Logs a message.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/cinch/logger.rb', line 112 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) ⇒ void
This method returns an undefined value.
Logs an outgoing IRC message.
90 91 92 |
# File 'lib/cinch/logger.rb', line 90 def outgoing() log(, :outgoing, :log) end |
#warn(message) ⇒ void
This method returns an undefined value.
Logs a warning message.
72 73 74 |
# File 'lib/cinch/logger.rb', line 72 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.
129 130 131 |
# File 'lib/cinch/logger.rb', line 129 def will_log?(level) LEVEL_ORDER.index(level) >= LEVEL_ORDER.index(@level) end |