Class: LogJam::LogJamLogger

Inherits:
Logger
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject

Attribute accessor/mutator declaration.



36
37
38
# File 'lib/logjam/logjam_logger.rb', line 36

def name
  @name
end

#prefixesObject

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 <<(message)
   @log << message
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, message=nil, program=nil, &block)
   @log.add(severity, message, program, &block)
end

#closeObject

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_formatObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


148
149
150
# File 'lib/logjam/logjam_logger.rb', line 148

def fatal?
   @log.fatal?
end

#formatterObject

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.

Returns:

  • (Boolean)


160
161
162
# File 'lib/logjam/logjam_logger.rb', line 160

def info?
   @log.info?
end

#levelObject

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

#loggerObject

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

#prognameObject

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_thresholdObject

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.

Returns:

  • (Boolean)


178
179
180
# File 'lib/logjam/logjam_logger.rb', line 178

def warn?
   @log.warn?
end