logjam 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/{README → README.md} +99 -136
- data/lib/logjam.rb +179 -3
- data/lib/logjam/configuration.rb +13 -0
- data/lib/logjam/exceptions.rb +6 -23
- data/lib/logjam/logger.rb +62 -0
- data/lib/logjam/object.rb +24 -24
- data/lib/logjam/version.rb +2 -2
- metadata +46 -22
- data/lib/logjam/logjam.rb +0 -395
- data/lib/logjam/logjam_logger.rb +0 -202
- data/lib/logjam/logjam_logger2.rb +0 -68
data/lib/logjam/logjam_logger.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Copyright (c), 2012 Peter Wood
|
4
|
-
# See the license.txt for details of the licensing of the code in this file.
|
5
|
-
|
6
|
-
module LogJam
|
7
|
-
# This class represents a specialization of the Ruby Logger class. The class
|
8
|
-
# retains a Ruby Logger instance within itself and delegates all standard
|
9
|
-
# logger calls to this instance. This allows for changes to the underlying
|
10
|
-
# logger without changing the containing one, thus bypassing people caching
|
11
|
-
# an instance.
|
12
|
-
class LogJamLogger < Logger
|
13
|
-
# Constructor for the LogJamLogger class. All parameters are passed
|
14
|
-
# straight through to create a standard Ruby Logger instance except
|
15
|
-
# when the first parameter is a Logger instance. In this case the
|
16
|
-
# Logger passed in is used rather than creating a new one.
|
17
|
-
#
|
18
|
-
# ==== Parameters
|
19
|
-
# logdev:: The log device to be used by the logger. This should
|
20
|
-
# either be a String containing a file path/name or an IO
|
21
|
-
# object that the logging details will be written to.
|
22
|
-
# shift_age:: The maximum number of old log files to retain or a String
|
23
|
-
# containing the rotation frequency for the log.
|
24
|
-
# shift_size:: The maximum size that the loggin output will be allowed
|
25
|
-
# to grow to before rotation occurs.
|
26
|
-
def initialize(logdev, shift_age=0, shift_size=1048576)
|
27
|
-
if logdev.kind_of?(Logger)
|
28
|
-
@log = logdev
|
29
|
-
else
|
30
|
-
@log = Logger.new(logdev, shift_age, shift_size)
|
31
|
-
end
|
32
|
-
@name = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
# Attribute accessor/mutator declaration.
|
36
|
-
attr_accessor :name
|
37
|
-
|
38
|
-
# Overload of the property fetcher provided by the contained Logger
|
39
|
-
# instance.
|
40
|
-
def formatter
|
41
|
-
@log.formatter
|
42
|
-
end
|
43
|
-
|
44
|
-
# Overload of the property updater provided by the contained Logger
|
45
|
-
# instance.
|
46
|
-
def formatter=(formatter)
|
47
|
-
@log.formatter = formatter
|
48
|
-
end
|
49
|
-
|
50
|
-
# Overload of the property fetcher provided by the contained Logger
|
51
|
-
# instance.
|
52
|
-
def level
|
53
|
-
@log.level
|
54
|
-
end
|
55
|
-
|
56
|
-
# Overload of the property updater provided by the contained Logger
|
57
|
-
# instance.
|
58
|
-
def level=(level)
|
59
|
-
@log.level = level
|
60
|
-
end
|
61
|
-
|
62
|
-
# Overload of the property fetcher provided by the contained Logger
|
63
|
-
# instance.
|
64
|
-
def progname
|
65
|
-
@log.progname
|
66
|
-
end
|
67
|
-
|
68
|
-
# Overload of the property updater provided by the contained Logger
|
69
|
-
# instance.
|
70
|
-
def progname=(name)
|
71
|
-
@log.progname = name
|
72
|
-
end
|
73
|
-
|
74
|
-
# Overload of the property fetcher provided by the contained Logger
|
75
|
-
# instance.
|
76
|
-
def sev_threshold
|
77
|
-
@log.sev_threshold
|
78
|
-
end
|
79
|
-
|
80
|
-
# Overload of the property updater provided by the contained Logger
|
81
|
-
# instance.
|
82
|
-
def sev_threshold=(threshold)
|
83
|
-
@log.sev_threshold = threshold
|
84
|
-
end
|
85
|
-
|
86
|
-
# Overload of the corresponding method on the Logger class to pass the
|
87
|
-
# call straight through to the contained logger.
|
88
|
-
def <<(message)
|
89
|
-
@log << message
|
90
|
-
end
|
91
|
-
|
92
|
-
# Overload of the corresponding method on the Logger class to pass the
|
93
|
-
# call straight through to the contained logger.
|
94
|
-
def add(severity, message=nil, program=nil, &block)
|
95
|
-
@log.add(severity, message, program, &block)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Overload of the corresponding method on the Logger class to pass the
|
99
|
-
# call straight through to the contained logger.
|
100
|
-
def close
|
101
|
-
@log.close
|
102
|
-
end
|
103
|
-
|
104
|
-
# Overload of the corresponding method on the Logger class to pass the
|
105
|
-
# call straight through to the contained logger.
|
106
|
-
def datetime_format
|
107
|
-
@log.datetime_format
|
108
|
-
end
|
109
|
-
|
110
|
-
# Overload of the corresponding method on the Logger class to pass the
|
111
|
-
# call straight through to the contained logger.
|
112
|
-
def datetime_format=(format)
|
113
|
-
@log.datetime_format = format
|
114
|
-
end
|
115
|
-
|
116
|
-
# Overload of the corresponding method on the Logger class to pass the
|
117
|
-
# call straight through to the contained logger.
|
118
|
-
def debug(program=nil, &block)
|
119
|
-
@log.debug(program, &block)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Overload of the corresponding method on the Logger class to pass the
|
123
|
-
# call straight through to the contained logger.
|
124
|
-
def debug?
|
125
|
-
@log.debug?
|
126
|
-
end
|
127
|
-
|
128
|
-
# Overload of the corresponding method on the Logger class to pass the
|
129
|
-
# call straight through to the contained logger.
|
130
|
-
def error(program=nil, &block)
|
131
|
-
@log.error(program, &block)
|
132
|
-
end
|
133
|
-
|
134
|
-
# Overload of the corresponding method on the Logger class to pass the
|
135
|
-
# call straight through to the contained logger.
|
136
|
-
def error?
|
137
|
-
@log.error?
|
138
|
-
end
|
139
|
-
|
140
|
-
# Overload of the corresponding method on the Logger class to pass the
|
141
|
-
# call straight through to the contained logger.
|
142
|
-
def fatal(program=nil, &block)
|
143
|
-
@log.fatal(program, &block)
|
144
|
-
end
|
145
|
-
|
146
|
-
# Overload of the corresponding method on the Logger class to pass the
|
147
|
-
# call straight through to the contained logger.
|
148
|
-
def fatal?
|
149
|
-
@log.fatal?
|
150
|
-
end
|
151
|
-
|
152
|
-
# Overload of the corresponding method on the Logger class to pass the
|
153
|
-
# call straight through to the contained logger.
|
154
|
-
def info(program=nil?, &block)
|
155
|
-
@log.info(program, &block)
|
156
|
-
end
|
157
|
-
|
158
|
-
# Overload of the corresponding method on the Logger class to pass the
|
159
|
-
# call straight through to the contained logger.
|
160
|
-
def info?
|
161
|
-
@log.info?
|
162
|
-
end
|
163
|
-
|
164
|
-
# Overload of the corresponding method on the Logger class to pass the
|
165
|
-
# call straight through to the contained logger.
|
166
|
-
def unknown(program=nil, &block)
|
167
|
-
@log.unknown(program, &block)
|
168
|
-
end
|
169
|
-
|
170
|
-
# Overload of the corresponding method on the Logger class to pass the
|
171
|
-
# call straight through to the contained logger.
|
172
|
-
def warn(program=nil, &block)
|
173
|
-
@log.warn(program, &block)
|
174
|
-
end
|
175
|
-
|
176
|
-
# Overload of the corresponding method on the Logger class to pass the
|
177
|
-
# call straight through to the contained logger.
|
178
|
-
def warn?
|
179
|
-
@log.warn?
|
180
|
-
end
|
181
|
-
|
182
|
-
# This method fetches the standard Ruby Logger instance contained within
|
183
|
-
# a LogJamLogger object.
|
184
|
-
def logger
|
185
|
-
@log
|
186
|
-
end
|
187
|
-
|
188
|
-
# This method updates the logger instance contained within a LogJamLogger
|
189
|
-
# object.
|
190
|
-
#
|
191
|
-
# ==== Parameters
|
192
|
-
# logger:: The object to set as the contained logger. This should be an
|
193
|
-
# instance of the standard Ruby Logger class or something
|
194
|
-
# compatible with this.
|
195
|
-
def logger=(logger)
|
196
|
-
@log = logger
|
197
|
-
end
|
198
|
-
|
199
|
-
# Aliases
|
200
|
-
alias :log :add
|
201
|
-
end
|
202
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Copyright (c), 2012 Peter Wood
|
4
|
-
# See the license.txt for details of the licensing of the code in this file.
|
5
|
-
|
6
|
-
module LogJam
|
7
|
-
# This class represents a specialization of the Ruby Logger class. The class
|
8
|
-
# retains a Ruby Logger instance within itself and delegates all standard
|
9
|
-
# logger calls to this instance. This allows for changes to the underlying
|
10
|
-
# logger without changing the containing one, thus bypassing people caching
|
11
|
-
# an instance.
|
12
|
-
class LogJamLogger < Logger
|
13
|
-
# Constructor for the LogJamLogger class. All parameters are passed
|
14
|
-
# straight through to create a standard Ruby Logger instance except
|
15
|
-
# when the first parameter is a Logger instance. In this case the
|
16
|
-
# Logger passed in is used rather than creating a new one.
|
17
|
-
#
|
18
|
-
# ==== Parameters
|
19
|
-
# logdev:: The log device to be used by the logger. This should
|
20
|
-
# either be a String containing a file path/name or an IO
|
21
|
-
# object that the logging details will be written to.
|
22
|
-
# shift_age:: The maximum number of old log files to retain or a String
|
23
|
-
# containing the rotation frequency for the log.
|
24
|
-
# shift_size:: The maximum size that the loggin output will be allowed
|
25
|
-
# to grow to before rotation occurs.
|
26
|
-
def initialize(logdev, shift_age=0, shift_size=1048576)
|
27
|
-
@log = (logdev.kind_of?(Logger) ? logdev : Logger.new(logdev, shift_age, shift_size))
|
28
|
-
@name = nil
|
29
|
-
@prefixes = {}
|
30
|
-
self.formatter = @log.formatter
|
31
|
-
end
|
32
|
-
|
33
|
-
# Attribute accessor/mutator declaration.
|
34
|
-
attr_accessor :name, :prefixes
|
35
|
-
|
36
|
-
# A definition of the method_missing method that passes all otherwise
|
37
|
-
# undefined method calls on to the contained logger instance.
|
38
|
-
#
|
39
|
-
# ==== Parameters
|
40
|
-
# method:: A Symbol containing the name of the method that was
|
41
|
-
# invoked but found to be missing.
|
42
|
-
# *arguments:: An array containing the arguments that were passed
|
43
|
-
# to the method call.
|
44
|
-
# &block:: Any block passed to the method call.
|
45
|
-
def method_missing(method, *arguments, &block)
|
46
|
-
if @log.responds_to? method
|
47
|
-
@log.send(method, *arguments, &block)
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# This method replaces the formatter assignment method on the logger
|
54
|
-
# to allow the addition of custom fields.
|
55
|
-
#
|
56
|
-
# ==== Parameters
|
57
|
-
# &block:: The block that contains the standard formatter to be
|
58
|
-
# set on the logger.
|
59
|
-
def formatter=(&block)
|
60
|
-
@log.formatter = proc do |severity, timestamp, program, message|
|
61
|
-
if @prefixes.include?(severity) || @prefixes.include?(:default)
|
62
|
-
message = "[#{(@prefixes[severity] || @prefixes[:default])}] #{message}"
|
63
|
-
end
|
64
|
-
block.call(severity, timestamp, program, message)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|