Class: Rodbot::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/rodbot/log.rb

Overview

Log facilities

Defined Under Namespace

Classes: LoggerIO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLog

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_loggerObject (readonly)

Default logger



9
10
11
# File 'lib/rodbot/log.rb', line 9

def default_logger
  @default_logger
end

#null_loggerObject (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

Parameters:

  • progname (String)

    progname used as default 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)

Returns:

  • (Boolean)


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

Parameters:

  • message (String)

    log message

  • level (Integer) (defaults to: Logger::INFO)

    any log level from Logger



25
26
27
# File 'lib/rodbot/log.rb', line 25

def log(message, level: Logger::INFO)
  @default_logger.log(level, message)
end