logsly 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/logsly/colors.rb +2 -2
- data/lib/logsly/logging182/appender.rb +290 -0
- data/lib/logsly/logging182/appenders/buffering.rb +398 -0
- data/lib/logsly/logging182/appenders/console.rb +81 -0
- data/lib/logsly/logging182/appenders/email.rb +178 -0
- data/lib/logsly/logging182/appenders/file.rb +85 -0
- data/lib/logsly/logging182/appenders/growl.rb +200 -0
- data/lib/logsly/logging182/appenders/io.rb +84 -0
- data/lib/logsly/logging182/appenders/rolling_file.rb +338 -0
- data/lib/logsly/logging182/appenders/string_io.rb +92 -0
- data/lib/logsly/logging182/appenders/syslog.rb +215 -0
- data/lib/logsly/logging182/appenders.rb +64 -0
- data/lib/logsly/logging182/color_scheme.rb +248 -0
- data/lib/logsly/logging182/config/configurator.rb +187 -0
- data/lib/logsly/logging182/config/yaml_configurator.rb +190 -0
- data/lib/logsly/logging182/diagnostic_context.rb +332 -0
- data/lib/logsly/logging182/layout.rb +132 -0
- data/lib/logsly/logging182/layouts/basic.rb +38 -0
- data/lib/logsly/logging182/layouts/parseable.rb +256 -0
- data/lib/logsly/logging182/layouts/pattern.rb +568 -0
- data/lib/logsly/logging182/layouts.rb +9 -0
- data/lib/logsly/logging182/log_event.rb +44 -0
- data/lib/logsly/logging182/logger.rb +509 -0
- data/lib/logsly/logging182/proxy.rb +59 -0
- data/lib/logsly/logging182/rails_compat.rb +36 -0
- data/lib/logsly/logging182/repository.rb +231 -0
- data/lib/logsly/logging182/root_logger.rb +60 -0
- data/lib/logsly/logging182/stats.rb +277 -0
- data/lib/logsly/logging182/utils.rb +231 -0
- data/lib/logsly/logging182.rb +559 -0
- data/lib/logsly/outputs.rb +5 -5
- data/lib/logsly/version.rb +1 -1
- data/lib/logsly.rb +6 -6
- data/logsly.gemspec +4 -2
- data/test/unit/colors_tests.rb +3 -3
- data/test/unit/logsly_tests.rb +14 -14
- data/test/unit/outputs_tests.rb +34 -24
- metadata +45 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
|
4
|
-
|
3
|
+
data.tar.gz: fdb3d320ab7c960ead493dea3487d22b888ec334
|
4
|
+
metadata.gz: 6597d31a9454d9c6975c24133145cfc5585f3437
|
5
5
|
SHA512:
|
6
|
-
|
7
|
-
|
6
|
+
data.tar.gz: 3570c61158197b4135d4ace0867444427ddfdb23c068fb13462495823bc8f2e04c95e34e2d5d75080d1f75cc4714bc9c45f609a432699edc68c55e327057ae69
|
7
|
+
metadata.gz: b18fd5ea0718979700ff59bcb56b8a4f54488c2668e185c9963fa26c519adc92096ad29adfe18b551ef7c771e425afefc851c369c8e3a4beac2c5dcef6bac24f
|
data/README.md
CHANGED
@@ -25,7 +25,9 @@ bg_logger.debug "something"
|
|
25
25
|
|
26
26
|
## Implementation
|
27
27
|
|
28
|
-
Logsly creates and delegates to a [Logging logger](https://github.com/TwP/logging). When you create an instance of your logger class, Logsly sets up and configures Logging for you.
|
28
|
+
Logsly creates and delegates to a [Logging logger](https://github.com/TwP/logging/tree/logging-1.8.2). When you create an instance of your logger class, Logsly sets up and configures Logging for you.
|
29
|
+
|
30
|
+
**Note**: [Logging v1.8.2](https://github.com/TwP/logging/tree/logging-1.8.2) is the last version that is Ruby 1.8.7 compatible. However, that version doesn't work in modern Ruby versions. Therefore I've taken the source from Logging v1.8.2 and brought it in manually as a submodule under the `Logsly::Logging182` namespace. I've tweaked the original source to allow properly requiring/referencing it as a submodule and to also make it work in modern Ruby. All source in the `Logsly::Logging182` namespace is [MIT License Copyright (c) 2012 Tim Pease](https://github.com/TwP/logging/tree/logging-1.8.2#license) and all credit is his.
|
29
31
|
|
30
32
|
## Settings
|
31
33
|
|
@@ -76,7 +78,7 @@ Define a named syslog output to use with your loggers. Takes the same parameter
|
|
76
78
|
|
77
79
|
### Patterns
|
78
80
|
|
79
|
-
Each output can define what pattern to format its messages with using the `pattern' method. See [Logging's patterns](https://github.com/TwP/logging/blob/
|
81
|
+
Each output can define what pattern to format its messages with using the `pattern' method. See [Logging's patterns](https://github.com/TwP/logging/blob/logging-1.8.2/lib/logging/layouts/pattern.rb) for details.
|
80
82
|
|
81
83
|
### Colors
|
82
84
|
|
@@ -93,7 +95,7 @@ Logsly.colors('my_colors') do
|
|
93
95
|
end
|
94
96
|
```
|
95
97
|
|
96
|
-
Define a named color scheme to use on your outputs. Essentially creates a [Logging::ColorScheme](https://github.com/TwP/logging/blob/
|
98
|
+
Define a named color scheme to use on your outputs. Essentially creates a [Logging::ColorScheme](https://github.com/TwP/logging/blob/logging-1.8.2/lib/logging/color_scheme.rb) object. See that file for configuration and details.
|
97
99
|
|
98
100
|
## Installation
|
99
101
|
|
data/lib/logsly/colors.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This class provides a DSL for setting color scheme values and lazy eval's
|
2
2
|
# the DSL to generate a Logging color scheme object.
|
3
|
-
# See https://github.com/TwP/logging/blob/
|
3
|
+
# See https://github.com/TwP/logging/blob/logging-1.8.2/lib/logging/color_scheme.rb
|
4
4
|
# for details on Logging color schemes.
|
5
5
|
|
6
6
|
module Logsly
|
@@ -19,7 +19,7 @@ module Logsly
|
|
19
19
|
|
20
20
|
def to_scheme(*args)
|
21
21
|
"#{@name}-#{args.map{|a| a.object_id}.join('-')}".tap do |scheme_name|
|
22
|
-
|
22
|
+
Logsly::Logging182.color_scheme(scheme_name, ColorsData.new(*args, &@build).to_scheme_opts)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -0,0 +1,290 @@
|
|
1
|
+
|
2
|
+
module Logsly::Logging182
|
3
|
+
|
4
|
+
# The +Appender+ class is provides methods for appending log events to a
|
5
|
+
# logging destination. The log events are formatted into strings using a
|
6
|
+
# Layout.
|
7
|
+
#
|
8
|
+
# All other Appenders inherit from this class which provides stub methods.
|
9
|
+
# Each subclass should provide a +write+ method that will write log
|
10
|
+
# messages to the logging destination.
|
11
|
+
#
|
12
|
+
# A private +sync+ method is provided for use by subclasses. It is used to
|
13
|
+
# synchronize writes to the logging destination, and can be used by
|
14
|
+
# subclasses to synchronize the closing or flushing of the logging
|
15
|
+
# destination.
|
16
|
+
#
|
17
|
+
class Appender
|
18
|
+
|
19
|
+
attr_reader :name, :layout, :level
|
20
|
+
|
21
|
+
# call-seq:
|
22
|
+
# Appender.new( name )
|
23
|
+
# Appender.new( name, :layout => layout )
|
24
|
+
#
|
25
|
+
# Creates a new appender using the given name. If no Layout is specified,
|
26
|
+
# then a Basic layout will be used. Any logging header supplied by the
|
27
|
+
# layout will be written to the logging destination when the Appender is
|
28
|
+
# created.
|
29
|
+
#
|
30
|
+
# Options:
|
31
|
+
#
|
32
|
+
# :layout => the layout to use when formatting log events
|
33
|
+
# :level => the level at which to log
|
34
|
+
# :encoding => encoding to use when writing messages (defaults to UTF-8)
|
35
|
+
#
|
36
|
+
def initialize( name, opts = {} )
|
37
|
+
::Logsly::Logging182.init unless ::Logsly::Logging182.initialized?
|
38
|
+
|
39
|
+
@name = name.to_s
|
40
|
+
@closed = false
|
41
|
+
|
42
|
+
self.layout = opts.getopt(:layout, ::Logsly::Logging182::Layouts::Basic.new)
|
43
|
+
self.level = opts.getopt(:level)
|
44
|
+
self.encoding = opts.fetch(:encoding, self.encoding)
|
45
|
+
|
46
|
+
@mutex = ReentrantMutex.new
|
47
|
+
|
48
|
+
if opts.getopt(:header, true)
|
49
|
+
header = @layout.header
|
50
|
+
|
51
|
+
unless header.nil? || header.empty?
|
52
|
+
begin
|
53
|
+
write(header)
|
54
|
+
rescue StandardError => err
|
55
|
+
::Logsly::Logging182.log_internal(-2) {err}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
::Logsly::Logging182::Appenders[@name] = self
|
61
|
+
end
|
62
|
+
|
63
|
+
# call-seq:
|
64
|
+
# append( event )
|
65
|
+
#
|
66
|
+
# Write the given _event_ to the logging destination. The log event will
|
67
|
+
# be processed through the Layout associated with the Appender.
|
68
|
+
#
|
69
|
+
def append( event )
|
70
|
+
if @closed
|
71
|
+
raise RuntimeError,
|
72
|
+
"appender '<#{self.class.name}: #{@name}>' is closed"
|
73
|
+
end
|
74
|
+
|
75
|
+
# only append if the event level is less than or equal to the configured
|
76
|
+
# appender level
|
77
|
+
unless @level > event.level
|
78
|
+
begin
|
79
|
+
write(event)
|
80
|
+
rescue StandardError => err
|
81
|
+
::Logsly::Logging182.log_internal(-2) {err}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# call-seq:
|
89
|
+
# appender << string
|
90
|
+
#
|
91
|
+
# Write the given _string_ to the logging destination "as is" -- no
|
92
|
+
# layout formatting will be performed.
|
93
|
+
#
|
94
|
+
def <<( str )
|
95
|
+
if @closed
|
96
|
+
raise RuntimeError,
|
97
|
+
"appender '<#{self.class.name}: #{@name}>' is closed"
|
98
|
+
end
|
99
|
+
|
100
|
+
unless @level >= ::Logsly::Logging182::LEVELS.length
|
101
|
+
begin
|
102
|
+
write(str)
|
103
|
+
rescue StandardError => err
|
104
|
+
::Logsly::Logging182.log_internal(-2) {err}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
# call-seq:
|
111
|
+
# level = :all
|
112
|
+
#
|
113
|
+
# Set the level for this appender; log events below this level will be
|
114
|
+
# ignored by this appender. The level can be either a +String+, a
|
115
|
+
# +Symbol+, or a +Fixnum+. An +ArgumentError+ is raised if this is not
|
116
|
+
# the case.
|
117
|
+
#
|
118
|
+
# There are two special levels -- "all" and "off". The former will
|
119
|
+
# enable recording of all log events. The latter will disable the
|
120
|
+
# recording of all events.
|
121
|
+
#
|
122
|
+
# Example:
|
123
|
+
#
|
124
|
+
# appender.level = :debug
|
125
|
+
# appender.level = "INFO"
|
126
|
+
# appender.level = 4
|
127
|
+
# appender.level = 'off'
|
128
|
+
# appender.level = :all
|
129
|
+
#
|
130
|
+
# These produce an +ArgumentError+
|
131
|
+
#
|
132
|
+
# appender.level = Object
|
133
|
+
# appender.level = -1
|
134
|
+
# appender.level = 1_000_000_000_000
|
135
|
+
#
|
136
|
+
def level=( level )
|
137
|
+
lvl = case level
|
138
|
+
when String, Symbol; ::Logsly::Logging182::level_num(level)
|
139
|
+
when Fixnum; level
|
140
|
+
when nil; 0
|
141
|
+
else
|
142
|
+
raise ArgumentError,
|
143
|
+
"level must be a String, Symbol, or Integer"
|
144
|
+
end
|
145
|
+
if lvl.nil? or lvl < 0 or lvl > ::Logsly::Logging182::LEVELS.length
|
146
|
+
raise ArgumentError, "unknown level was given '#{level}'"
|
147
|
+
end
|
148
|
+
|
149
|
+
@level = lvl
|
150
|
+
end
|
151
|
+
|
152
|
+
# call-seq
|
153
|
+
# appender.layout = Logsly::Logging182::Layouts::Basic.new
|
154
|
+
#
|
155
|
+
# Sets the layout to be used by this appender.
|
156
|
+
#
|
157
|
+
def layout=( layout )
|
158
|
+
unless layout.kind_of? ::Logsly::Logging182::Layout
|
159
|
+
raise TypeError,
|
160
|
+
"#{layout.inspect} is not a kind of 'Logsly::Logging182::Layout'"
|
161
|
+
end
|
162
|
+
@layout = layout
|
163
|
+
end
|
164
|
+
|
165
|
+
# call-seq:
|
166
|
+
# close( footer = true )
|
167
|
+
#
|
168
|
+
# Close the appender and writes the layout footer to the logging
|
169
|
+
# destination if the _footer_ flag is set to +true+. Log events will
|
170
|
+
# no longer be written to the logging destination after the appender
|
171
|
+
# is closed.
|
172
|
+
#
|
173
|
+
def close( footer = true )
|
174
|
+
return self if @closed
|
175
|
+
::Logsly::Logging182::Appenders.remove(@name)
|
176
|
+
@closed = true
|
177
|
+
|
178
|
+
flush
|
179
|
+
|
180
|
+
if footer
|
181
|
+
footer = @layout.footer
|
182
|
+
unless footer.nil? || footer.empty?
|
183
|
+
begin
|
184
|
+
write(footer)
|
185
|
+
rescue StandardError => err
|
186
|
+
::Logsly::Logging182.log_internal(-2) {err}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
self
|
191
|
+
end
|
192
|
+
|
193
|
+
# call-seq:
|
194
|
+
# closed?
|
195
|
+
#
|
196
|
+
# Returns +true+ if the appender has been closed; returns +false+
|
197
|
+
# otherwise. When an appender is closed, no more log events can be
|
198
|
+
# written to the logging destination.
|
199
|
+
#
|
200
|
+
def closed?
|
201
|
+
@closed
|
202
|
+
end
|
203
|
+
|
204
|
+
# Reopen the connection to the underlying logging destination. If the
|
205
|
+
# connection is currently closed then it will be opened. If the connection
|
206
|
+
# is currently open then it will be closed and immediately opened.
|
207
|
+
#
|
208
|
+
def reopen
|
209
|
+
@closed = false
|
210
|
+
self
|
211
|
+
end
|
212
|
+
|
213
|
+
# call-seq:
|
214
|
+
# flush
|
215
|
+
#
|
216
|
+
# Call +flush+ to force an appender to write out any buffered log events.
|
217
|
+
# Similar to IO#flush, so use in a similar fashion.
|
218
|
+
#
|
219
|
+
def flush
|
220
|
+
self
|
221
|
+
end
|
222
|
+
|
223
|
+
# call-seq:
|
224
|
+
# inspect => string
|
225
|
+
#
|
226
|
+
# Returns a string representation of the appender.
|
227
|
+
#
|
228
|
+
def inspect
|
229
|
+
"<%s:0x%x name=\"%s\">" % [
|
230
|
+
self.class.name.sub(%r/^Logsly::Logging182::/, ''),
|
231
|
+
self.object_id,
|
232
|
+
self.name
|
233
|
+
]
|
234
|
+
end
|
235
|
+
|
236
|
+
# Returns the current Encoding for the appender or nil if an encoding has
|
237
|
+
# not been set.
|
238
|
+
#
|
239
|
+
def encoding
|
240
|
+
return @encoding if defined? @encoding
|
241
|
+
@encoding = Object.const_defined?(:Encoding) ? Encoding.default_external : nil
|
242
|
+
end
|
243
|
+
|
244
|
+
# Set the appender encoding to the given value. The value can either be an
|
245
|
+
# Encoding instance or a String or Symbol referring to a valid encoding.
|
246
|
+
#
|
247
|
+
# This method only applies to Ruby 1.9 or later. The encoding will always be
|
248
|
+
# nil for older Rubies.
|
249
|
+
#
|
250
|
+
# value - The encoding as a String, Symbol, or Encoding instance.
|
251
|
+
#
|
252
|
+
# Raises ArgumentError if the value is not a valid encoding.
|
253
|
+
#
|
254
|
+
def encoding=( value )
|
255
|
+
if value.nil?
|
256
|
+
@encoding = nil
|
257
|
+
else
|
258
|
+
@encoding = Object.const_defined?(:Encoding) ? Encoding.find(value.to_s) : nil
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
private
|
264
|
+
|
265
|
+
# call-seq:
|
266
|
+
# write( event )
|
267
|
+
#
|
268
|
+
# Writes the given _event_ to the logging destination. Subclasses should
|
269
|
+
# provide an implementation of this method. The _event_ can be either a
|
270
|
+
# LogEvent or a String. If a LogEvent, then it will be formatted using
|
271
|
+
# the layout given to the appender when it was created.
|
272
|
+
#
|
273
|
+
def write( event )
|
274
|
+
nil
|
275
|
+
end
|
276
|
+
|
277
|
+
# call-seq:
|
278
|
+
# sync { block }
|
279
|
+
#
|
280
|
+
# Obtains an exclusive lock, runs the block, and releases the lock when
|
281
|
+
# the block completes. This method is re-entrant so that a single thread
|
282
|
+
# can call +sync+ multiple times without hanging the thread.
|
283
|
+
#
|
284
|
+
def sync( &block )
|
285
|
+
@mutex.synchronize(&block)
|
286
|
+
end
|
287
|
+
|
288
|
+
end # class Appender
|
289
|
+
end # module Logsly::Logging182
|
290
|
+
|