Module: DogTrainer::Logging

Included in:
API
Defined in:
lib/dogtrainer/logging.rb

Overview

module to setup logging per-class throughout DogTrainer

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.formatterObject (readonly)

Returns the value of attribute formatter.



50
51
52
# File 'lib/dogtrainer/logging.rb', line 50

def formatter
  @formatter
end

.levelObject

Returns the value of attribute level.



45
46
47
# File 'lib/dogtrainer/logging.rb', line 45

def level
  @level
end

.outputterObject (readonly)

Returns the value of attribute outputter.



55
56
57
# File 'lib/dogtrainer/logging.rb', line 55

def outputter
  @outputter
end

Class Method Details

.debug_formatterLog4r::PatternFormatter

Return a new log formatter with the debug-level pattern

Returns:

  • (Log4r::PatternFormatter)


67
68
69
# File 'lib/dogtrainer/logging.rb', line 67

def debug_formatter
  Log4r::PatternFormatter.new(pattern: '[%d - %C - %l] %m')
end

.default_formatterLog4r::PatternFormatter

Return a new log formatter with the default pattern

Returns:

  • (Log4r::PatternFormatter)


60
61
62
# File 'lib/dogtrainer/logging.rb', line 60

def default_formatter
  Log4r::PatternFormatter.new(pattern: '%l\t -> %m')
end

.default_outputterLog4r::StderrOutputter

Return the default log outputter (console)

Returns:

  • (Log4r::StderrOutputter)


74
75
76
# File 'lib/dogtrainer/logging.rb', line 74

def default_outputter
  Log4r::StderrOutputter.new 'console'
end

Instance Method Details

#loggerLog4r::Logger

Return a logger for the current class

Returns:

  • (Log4r::Logger)


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dogtrainer/logging.rb', line 16

def logger
  if @logger.nil?
    name = logger_name
    if Log4r::Logger[name]
      @logger = Log4r::Logger[name]
    else
      @logger = Log4r::Logger.new(name)
      @logger.add(DogTrainer::Logging.outputter)
    end
  end
  @logger
end

#logger_nameString

Return the name of the class this logger is part of

Returns:

  • (String)

    logger class name



9
10
11
# File 'lib/dogtrainer/logging.rb', line 9

def logger_name
  self.class.to_s
end