Class: Rodbot::Log
- Inherits:
-
Object
- Object
- Rodbot::Log
- Defined in:
- lib/rodbot/log.rb
Overview
Log facilities
Defined Under Namespace
Classes: LoggerIO
Instance Attribute Summary collapse
-
#default_logger ⇒ Object
readonly
Default logger.
-
#null_logger ⇒ Object
readonly
Black hole logger.
Class Method Summary collapse
-
.logger(progname) ⇒ Object
Create a logger instance for the given scope.
-
.std? ⇒ Boolean
Whether currently configured to log to a std device (
STDOUT
orSTDERR
).
Instance Method Summary collapse
-
#initialize ⇒ Log
constructor
A new instance of Log.
-
#log(message, level: Logger::INFO) ⇒ Object
Add a log entry to the default log.
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
14 15 16 17 |
# File 'lib/rodbot/log.rb', line 14 def initialize @default_logger = self.class.logger('rodbot') @null_logger = Logger.new(File::NULL) end |
Instance Attribute Details
#default_logger ⇒ Object (readonly)
Default logger
9 10 11 |
# File 'lib/rodbot/log.rb', line 9 def default_logger @default_logger end |
#null_logger ⇒ Object (readonly)
Black hole logger
12 13 14 |
# File 'lib/rodbot/log.rb', line 12 def null_logger @null_logger end |
Class Method Details
.logger(progname) ⇒ Object
Create a logger instance for the given scope
32 33 34 35 36 |
# File 'lib/rodbot/log.rb', line 32 def self.logger(progname) Logger.new(Rodbot.config(:log, :to), progname: progname).tap do |logger| logger.level = Rodbot.config(:log, :level) end end |
.std? ⇒ Boolean
Whether currently configured to log to a std device (STDOUT
or STDERR
)
41 42 43 |
# File 'lib/rodbot/log.rb', line 41 def self.std? [STDOUT, STDERR].include? Rodbot.config(:log, :to) end |
Instance Method Details
#log(message, level: Logger::INFO) ⇒ Object
Note:
Use the Rodbot.log
shortcut to access this method!
Add a log entry to the default log
25 26 27 |
# File 'lib/rodbot/log.rb', line 25 def log(, level: Logger::INFO) @default_logger.log(level, ) end |