Class: LogJam::LogJamLogger
- Defined in:
- lib/logjam/logjam_logger.rb,
lib/logjam/logjam_logger2.rb
Overview
This class represents a specialization of the Ruby Logger class. The class retains a Ruby Logger instance within itself and delegates all standard logger calls to this instance. This allows for changes to the underlying logger without changing the containing one, thus bypassing people caching an instance.
Instance Attribute Summary collapse
-
#name ⇒ Object
Attribute accessor/mutator declaration.
-
#prefixes ⇒ Object
Attribute accessor/mutator declaration.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#add(severity, message = nil, program = nil, &block) ⇒ Object
(also: #log)
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#close ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#datetime_format ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#datetime_format=(format) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#debug(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#debug? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#error(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#error? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#fatal(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#fatal? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#formatter ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
-
#formatter=(&block) ⇒ Object
This method replaces the formatter assignment method on the logger to allow the addition of custom fields.
-
#info(program = nil?, , &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#info? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#initialize(logdev, shift_age = 0, shift_size = 1048576) ⇒ LogJamLogger
constructor
Constructor for the LogJamLogger class.
-
#level ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
-
#level=(level) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
-
#logger ⇒ Object
This method fetches the standard Ruby Logger instance contained within a LogJamLogger object.
-
#logger=(logger) ⇒ Object
This method updates the logger instance contained within a LogJamLogger object.
-
#method_missing(method, *arguments, &block) ⇒ Object
A definition of the method_missing method that passes all otherwise undefined method calls on to the contained logger instance.
-
#progname ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
-
#progname=(name) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
-
#sev_threshold ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
-
#sev_threshold=(threshold) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
-
#unknown(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#warn(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
-
#warn? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
Constructor Details
#initialize(logdev, shift_age = 0, shift_size = 1048576) ⇒ LogJamLogger
Constructor for the LogJamLogger class. All parameters are passed straight through to create a standard Ruby Logger instance except when the first parameter is a Logger instance. In this case the Logger passed in is used rather than creating a new one.
Parameters
- logdev
-
The log device to be used by the logger. This should either be a String containing a file path/name or an IO object that the logging details will be written to.
- shift_age
-
The maximum number of old log files to retain or a String containing the rotation frequency for the log.
- shift_size
-
The maximum size that the loggin output will be allowed to grow to before rotation occurs.
26 27 28 29 30 31 32 33 |
# File 'lib/logjam/logjam_logger.rb', line 26 def initialize(logdev, shift_age=0, shift_size=1048576) if logdev.kind_of?(Logger) @log = logdev else @log = Logger.new(logdev, shift_age, shift_size) end @name = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
A definition of the method_missing method that passes all otherwise undefined method calls on to the contained logger instance.
Parameters
- method
-
A Symbol containing the name of the method that was invoked but found to be missing.
- *arguments
-
An array containing the arguments that were passed to the method call.
- &block
-
Any block passed to the method call.
45 46 47 48 49 50 51 |
# File 'lib/logjam/logjam_logger2.rb', line 45 def method_missing(method, *arguments, &block) if @log.responds_to? method @log.send(method, *arguments, &block) else super end end |
Instance Attribute Details
#name ⇒ Object
Attribute accessor/mutator declaration.
36 37 38 |
# File 'lib/logjam/logjam_logger.rb', line 36 def name @name end |
#prefixes ⇒ Object
Attribute accessor/mutator declaration.
34 35 36 |
# File 'lib/logjam/logjam_logger2.rb', line 34 def prefixes @prefixes end |
Instance Method Details
#<<(message) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
88 89 90 |
# File 'lib/logjam/logjam_logger.rb', line 88 def <<() @log << end |
#add(severity, message = nil, program = nil, &block) ⇒ Object Also known as: log
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
94 95 96 |
# File 'lib/logjam/logjam_logger.rb', line 94 def add(severity, =nil, program=nil, &block) @log.add(severity, , program, &block) end |
#close ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
100 101 102 |
# File 'lib/logjam/logjam_logger.rb', line 100 def close @log.close end |
#datetime_format ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
106 107 108 |
# File 'lib/logjam/logjam_logger.rb', line 106 def datetime_format @log.datetime_format end |
#datetime_format=(format) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
112 113 114 |
# File 'lib/logjam/logjam_logger.rb', line 112 def datetime_format=(format) @log.datetime_format = format end |
#debug(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
118 119 120 |
# File 'lib/logjam/logjam_logger.rb', line 118 def debug(program=nil, &block) @log.debug(program, &block) end |
#debug? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
124 125 126 |
# File 'lib/logjam/logjam_logger.rb', line 124 def debug? @log.debug? end |
#error(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
130 131 132 |
# File 'lib/logjam/logjam_logger.rb', line 130 def error(program=nil, &block) @log.error(program, &block) end |
#error? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
136 137 138 |
# File 'lib/logjam/logjam_logger.rb', line 136 def error? @log.error? end |
#fatal(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
142 143 144 |
# File 'lib/logjam/logjam_logger.rb', line 142 def fatal(program=nil, &block) @log.fatal(program, &block) end |
#fatal? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
148 149 150 |
# File 'lib/logjam/logjam_logger.rb', line 148 def fatal? @log.fatal? end |
#formatter ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
40 41 42 |
# File 'lib/logjam/logjam_logger.rb', line 40 def formatter @log.formatter end |
#formatter=(&block) ⇒ Object
This method replaces the formatter assignment method on the logger to allow the addition of custom fields.
Parameters
- &block
-
The block that contains the standard formatter to be set on the logger.
46 47 48 |
# File 'lib/logjam/logjam_logger.rb', line 46 def formatter=(formatter) @log.formatter = formatter end |
#info(program = nil?, , &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
154 155 156 |
# File 'lib/logjam/logjam_logger.rb', line 154 def info(program=nil?, &block) @log.info(program, &block) end |
#info? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
160 161 162 |
# File 'lib/logjam/logjam_logger.rb', line 160 def info? @log.info? end |
#level ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
52 53 54 |
# File 'lib/logjam/logjam_logger.rb', line 52 def level @log.level end |
#level=(level) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
58 59 60 |
# File 'lib/logjam/logjam_logger.rb', line 58 def level=(level) @log.level = level end |
#logger ⇒ Object
This method fetches the standard Ruby Logger instance contained within a LogJamLogger object.
184 185 186 |
# File 'lib/logjam/logjam_logger.rb', line 184 def logger @log end |
#logger=(logger) ⇒ Object
This method updates the logger instance contained within a LogJamLogger object.
Parameters
- logger
-
The object to set as the contained logger. This should be an instance of the standard Ruby Logger class or something compatible with this.
195 196 197 |
# File 'lib/logjam/logjam_logger.rb', line 195 def logger=(logger) @log = logger end |
#progname ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
64 65 66 |
# File 'lib/logjam/logjam_logger.rb', line 64 def progname @log.progname end |
#progname=(name) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
70 71 72 |
# File 'lib/logjam/logjam_logger.rb', line 70 def progname=(name) @log.progname = name end |
#sev_threshold ⇒ Object
Overload of the property fetcher provided by the contained Logger instance.
76 77 78 |
# File 'lib/logjam/logjam_logger.rb', line 76 def sev_threshold @log.sev_threshold end |
#sev_threshold=(threshold) ⇒ Object
Overload of the property updater provided by the contained Logger instance.
82 83 84 |
# File 'lib/logjam/logjam_logger.rb', line 82 def sev_threshold=(threshold) @log.sev_threshold = threshold end |
#unknown(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
166 167 168 |
# File 'lib/logjam/logjam_logger.rb', line 166 def unknown(program=nil, &block) @log.unknown(program, &block) end |
#warn(program = nil, &block) ⇒ Object
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
172 173 174 |
# File 'lib/logjam/logjam_logger.rb', line 172 def warn(program=nil, &block) @log.warn(program, &block) end |
#warn? ⇒ Boolean
Overload of the corresponding method on the Logger class to pass the call straight through to the contained logger.
178 179 180 |
# File 'lib/logjam/logjam_logger.rb', line 178 def warn? @log.warn? end |