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
-
.formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
.level ⇒ Object
Returns the value of attribute level.
-
.outputter ⇒ Object
readonly
Returns the value of attribute outputter.
Class Method Summary collapse
-
.debug_formatter ⇒ Log4r::PatternFormatter
Return a new log formatter with the debug-level pattern.
-
.default_formatter ⇒ Log4r::PatternFormatter
Return a new log formatter with the default pattern.
-
.default_outputter ⇒ Log4r::StderrOutputter
Return the default log outputter (console).
Instance Method Summary collapse
-
#logger ⇒ Log4r::Logger
Return a logger for the current class.
-
#logger_name ⇒ String
Return the name of the class this logger is part of.
Class Attribute Details
.formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
50 51 52 |
# File 'lib/dogtrainer/logging.rb', line 50 def formatter @formatter end |
.level ⇒ Object
Returns the value of attribute level.
45 46 47 |
# File 'lib/dogtrainer/logging.rb', line 45 def level @level end |
.outputter ⇒ Object (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_formatter ⇒ Log4r::PatternFormatter
Return a new log formatter with the debug-level pattern
67 68 69 |
# File 'lib/dogtrainer/logging.rb', line 67 def debug_formatter Log4r::PatternFormatter.new(pattern: '[%d - %C - %l] %m') end |
.default_formatter ⇒ Log4r::PatternFormatter
Return a new log formatter with the default pattern
60 61 62 |
# File 'lib/dogtrainer/logging.rb', line 60 def default_formatter Log4r::PatternFormatter.new(pattern: '%l\t -> %m') end |
.default_outputter ⇒ Log4r::StderrOutputter
Return the default log outputter (console)
74 75 76 |
# File 'lib/dogtrainer/logging.rb', line 74 def default_outputter Log4r::StderrOutputter.new 'console' end |
Instance Method Details
#logger ⇒ Log4r::Logger
Return a logger for the current class
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_name ⇒ String
Return the name of the class this logger is part of
9 10 11 |
# File 'lib/dogtrainer/logging.rb', line 9 def logger_name self.class.to_s end |