logging 2.0.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +8 -5
- data/History.txt +59 -0
- data/LICENSE +22 -0
- data/README.md +20 -41
- data/Rakefile +2 -2
- data/examples/appenders.rb +1 -1
- data/examples/layouts.rb +1 -1
- data/examples/lazy.rb +1 -1
- data/examples/mdc.rb +2 -2
- data/examples/rails4.rb +21 -0
- data/examples/reusing_layouts.rb +51 -0
- data/lib/logging.rb +99 -9
- data/lib/logging/appender.rb +13 -34
- data/lib/logging/appenders/buffering.rb +130 -59
- data/lib/logging/appenders/console.rb +68 -57
- data/lib/logging/appenders/file.rb +43 -22
- data/lib/logging/appenders/io.rb +22 -16
- data/lib/logging/appenders/rolling_file.rb +60 -26
- data/lib/logging/appenders/string_io.rb +1 -1
- data/lib/logging/appenders/syslog.rb +3 -4
- data/lib/logging/color_scheme.rb +1 -1
- data/lib/logging/diagnostic_context.rb +100 -73
- data/lib/logging/layout.rb +144 -16
- data/lib/logging/layouts/parseable.rb +50 -12
- data/lib/logging/layouts/pattern.rb +8 -9
- data/lib/logging/log_event.rb +19 -12
- data/lib/logging/logger.rb +117 -95
- data/lib/logging/proxy.rb +1 -1
- data/lib/logging/rails_compat.rb +4 -13
- data/lib/logging/version.rb +1 -1
- data/logging.gemspec +31 -32
- data/script/console +8 -0
- data/test/appenders/{test_periodic_flushing.rb → test_async_flushing.rb} +67 -14
- data/test/appenders/test_buffered_io.rb +19 -18
- data/test/appenders/test_console.rb +55 -12
- data/test/appenders/test_file.rb +48 -28
- data/test/appenders/test_rolling_file.rb +18 -12
- data/test/appenders/test_syslog.rb +6 -0
- data/test/benchmark.rb +42 -18
- data/test/layouts/test_json.rb +14 -1
- data/test/layouts/test_nested_exceptions.rb +124 -0
- data/test/layouts/test_pattern.rb +16 -3
- data/test/layouts/test_yaml.rb +15 -1
- data/test/performance.rb +66 -0
- data/test/setup.rb +26 -30
- data/test/test_appender.rb +2 -4
- data/test/test_layout.rb +49 -0
- data/test/test_log_event.rb +10 -2
- data/test/test_logger.rb +20 -3
- data/test/test_logging.rb +75 -4
- data/test/test_mapped_diagnostic_context.rb +15 -6
- data/test/test_nested_diagnostic_context.rb +6 -1
- metadata +23 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ec479cf977c621a6b42426cfe7c478a97e106c23762f3608ee67fcbaa49b324
|
4
|
+
data.tar.gz: 6a0c0107cf3c1a1f7504e19e85a9505ad94c4a84991d01eb6c65191257a01163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cd72dabcd8b878b73f69ec8a445678b14635ca1c115576ef148a7160673f83939d7706e5d673c32ed11ef2c48046cc7a50bd2c2c0795b2fa79c35e9d4bccf87
|
7
|
+
data.tar.gz: 23422872b58d1bd0e0a146f64e4bb792ef5208da309b16e7650d5c74ca9969b12e6e65dd5ef79a90ce39e0d6c51dbc7514f7a2e913ec74b2e8404a06aefa8975
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,62 @@
|
|
1
|
+
== 2.3.0 / 2020-07-04
|
2
|
+
|
3
|
+
Enhancements
|
4
|
+
- all appender output is now synchronized [PR #219]
|
5
|
+
- renamed the `LogEvent#method` to no longer conflict with `Kernel#method` [PR #218]
|
6
|
+
- @bhuga (not the Fortnite star) added a `raise_errors` method for debugging [PR #203]
|
7
|
+
- thanks to @olleolleolle for keeping on top of Travis and Ruby versions
|
8
|
+
|
9
|
+
Bug Fixes
|
10
|
+
- conosle appenders can be reopened [PR #220]
|
11
|
+
- fixed a race condition in the rolling file appender [PR #216]
|
12
|
+
- fixed a race condition when opening log file destinations [PR #208 #217]
|
13
|
+
- @MikaelSmith fixed a race condition in Logger creation [PR #201]
|
14
|
+
- documentation bug fixes [PR #184 #185 #188 #194 #209]
|
15
|
+
|
16
|
+
== 2.2.2 / 2017-04-11
|
17
|
+
|
18
|
+
Enhancements
|
19
|
+
- limit the depth of nested exceptions [PR #167]
|
20
|
+
|
21
|
+
== 2.2.1 / 2017-04-09
|
22
|
+
|
23
|
+
Enhancements
|
24
|
+
- show exception `cause` if one exists [PR #165]
|
25
|
+
|
26
|
+
== 2.2.0 / 2017-03-09
|
27
|
+
|
28
|
+
Enhancements
|
29
|
+
- diagnostic context inheritance is now optional [PR #160]
|
30
|
+
- add support for setting a UTC offset [PR #157]
|
31
|
+
- setting a basepath for call tracing [PR #154]
|
32
|
+
|
33
|
+
Bug Fixes
|
34
|
+
- use thread-local variables for diagnostic contexts [PR #162]
|
35
|
+
- replace `Fixnum` with `Integer` [PR #161]
|
36
|
+
- fixed a race condition in the rolling file appender [PR #151]
|
37
|
+
|
38
|
+
Deprecations
|
39
|
+
- dropped Ruby 1.9 support
|
40
|
+
|
41
|
+
== 2.1.0 / 2016-03-13
|
42
|
+
|
43
|
+
Enhancements
|
44
|
+
- appender factories now fail explicitly on bad arguments [PR #117]
|
45
|
+
- console loggers (stdout, stderr) use `write` for compatibility [PR #127]
|
46
|
+
- allow whitespace in traced method names [PR #128]
|
47
|
+
- accessor methods for `backtrace` settings [PR #134]
|
48
|
+
- asynchronous writing from buffered appenders [PR #135]
|
49
|
+
- improve date format performance when outputting microseconds [PR #136]
|
50
|
+
- added some thread safety to log level setters [PR #137]
|
51
|
+
- use `write` everywhere instead of `syswrite` [PR #138]
|
52
|
+
|
53
|
+
Bug Fixes
|
54
|
+
- fixing encodings in tests [PR #116]
|
55
|
+
- fix Rails4 logger compatibility [PR #121]
|
56
|
+
- explicitly adding the MIT license [PR #123]
|
57
|
+
- update `object_id` format in inspect methods [PR #133]
|
58
|
+
- fixed Travis-CI tests
|
59
|
+
|
1
60
|
== 2.0.0 / 2015-03-28
|
2
61
|
|
3
62
|
Enhancements
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2007-2016 Tim Pease
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
## Logging
|
2
|
-
by Tim Pease [![](https://secure.travis-ci.org/TwP/logging.
|
2
|
+
by Tim Pease [![](https://secure.travis-ci.org/TwP/logging.svg)](https://travis-ci.org/TwP/logging)
|
3
3
|
|
4
4
|
* [Homepage](http://rubygems.org/gems/logging)
|
5
5
|
* [Github Project](https://github.com/TwP/logging)
|
6
6
|
|
7
7
|
### Description
|
8
8
|
|
9
|
-
Logging is a flexible logging library for use in Ruby programs based on the
|
9
|
+
**Logging** is a flexible logging library for use in Ruby programs based on the
|
10
10
|
design of Java's log4j library. It features a hierarchical logging system,
|
11
11
|
custom level names, multiple output destinations per log event, custom
|
12
12
|
formatting, and more.
|
@@ -82,23 +82,23 @@ class SecondClass
|
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
85
|
-
There are many more examples in the [examples folder](
|
86
|
-
|
87
|
-
|
88
|
-
* [simple.rb](
|
89
|
-
* [rspec_integration.rb](
|
90
|
-
* [loggers.rb](
|
91
|
-
* [classes.rb](
|
92
|
-
* [hierarchies.rb](
|
93
|
-
* [names.rb](
|
94
|
-
* [lazy.rb](
|
95
|
-
* [appenders.rb](
|
96
|
-
* [layouts.rb](
|
97
|
-
* [
|
98
|
-
* [
|
99
|
-
* [
|
100
|
-
* [fork.rb](
|
101
|
-
* [mdc.rb](
|
85
|
+
There are many more examples in the [examples folder](/examples) of the logging
|
86
|
+
package. The recommended reading order is the following:
|
87
|
+
|
88
|
+
* [simple.rb](/examples/simple.rb)
|
89
|
+
* [rspec_integration.rb](/examples/rspec_integration.rb)
|
90
|
+
* [loggers.rb](/examples/loggers.rb)
|
91
|
+
* [classes.rb](/examples/classes.rb)
|
92
|
+
* [hierarchies.rb](/examples/hierarchies.rb)
|
93
|
+
* [names.rb](/examples/names.rb)
|
94
|
+
* [lazy.rb](/examples/lazy.rb)
|
95
|
+
* [appenders.rb](/examples/appenders.rb)
|
96
|
+
* [layouts.rb](/examples/layouts.rb)
|
97
|
+
* [reusing_layouts.rb](/examples/reusing_layouts.rb)
|
98
|
+
* [formatting.rb](/examples/formatting.rb)
|
99
|
+
* [colorization.rb](/examples/colorization.rb)
|
100
|
+
* [fork.rb](/examples/fork.rb)
|
101
|
+
* [mdc.rb](/examples/mdc.rb)
|
102
102
|
|
103
103
|
### Extending
|
104
104
|
|
@@ -135,25 +135,4 @@ After this is done you can rake `rake -T` to see the available rake tasks.
|
|
135
135
|
|
136
136
|
### License
|
137
137
|
|
138
|
-
The MIT License
|
139
|
-
|
140
|
-
Copyright (c) 2015 Tim Pease
|
141
|
-
|
142
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
143
|
-
a copy of this software and associated documentation files (the
|
144
|
-
'Software'), to deal in the Software without restriction, including
|
145
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
146
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
147
|
-
permit persons to whom the Software is furnished to do so, subject to
|
148
|
-
the following conditions:
|
149
|
-
|
150
|
-
The above copyright notice and this permission notice shall be
|
151
|
-
included in all copies or substantial portions of the Software.
|
152
|
-
|
153
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
154
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
155
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
156
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
157
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
158
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
159
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
138
|
+
The MIT License - see the [LICENSE](/LICENSE) file for the full text.
|
data/Rakefile
CHANGED
@@ -26,9 +26,9 @@ Bones {
|
|
26
26
|
use_gmail
|
27
27
|
|
28
28
|
depend_on 'little-plugger', '~> 1.1'
|
29
|
-
depend_on 'multi_json', '~> 1.
|
29
|
+
depend_on 'multi_json', '~> 1.14'
|
30
30
|
|
31
|
-
depend_on '
|
31
|
+
depend_on 'test-unit', '~> 3.3', :development => true
|
32
32
|
depend_on 'bones-git', '~> 1.3', :development => true
|
33
33
|
#depend_on 'bones-rcov', :development => true
|
34
34
|
}
|
data/examples/appenders.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# :stopdoc:
|
2
2
|
#
|
3
3
|
# Appenders are used to output log events to some logging destination. The
|
4
|
-
# same log event can be sent to multiple
|
4
|
+
# same log event can be sent to multiple destinations by associating
|
5
5
|
# multiple appenders with the logger.
|
6
6
|
#
|
7
7
|
# The following is a list of all the available appenders and a brief
|
data/examples/layouts.rb
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
log.level = :debug
|
34
34
|
|
35
35
|
log.debug "a very nice little debug message"
|
36
|
-
log.info "things are operating
|
36
|
+
log.info "things are operating normally"
|
37
37
|
log.warn "this is your last warning"
|
38
38
|
log.error StandardError.new("something went horribly wrong")
|
39
39
|
log.fatal "I Die!"
|
data/examples/lazy.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# It happens sometimes that it is very expensive to construct a logging
|
4
4
|
# message; for example, if a large object structure has to be traversed
|
5
|
-
# during
|
5
|
+
# during execution of an `object.to_s` method. It would be convenient to
|
6
6
|
# delay creation of the message until the log event actually takes place.
|
7
7
|
#
|
8
8
|
# For example, with a logger configured only to show WARN messages and higher,
|
data/examples/mdc.rb
CHANGED
@@ -29,9 +29,9 @@
|
|
29
29
|
Logging.mdc['first'] = 'John'
|
30
30
|
Logging.mdc['last'] = 'Doe'
|
31
31
|
|
32
|
-
# in this first thread we will log some quotes by
|
32
|
+
# in this first thread we will log some quotes by Alan Rickman
|
33
33
|
t1 = Thread.new {
|
34
|
-
Logging.mdc['first'] = '
|
34
|
+
Logging.mdc['first'] = 'Alan'
|
35
35
|
Logging.mdc['last'] = 'Rickman'
|
36
36
|
|
37
37
|
[ %q{I've never been able to plan my life. I just lurch from indecision to indecision.},
|
data/examples/rails4.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
#
|
3
|
+
# Rails 4 allows you to hook up multiple loggers (even those external to this gem)
|
4
|
+
# so you can use a single Rails.logger statement. For Rails developers, this is
|
5
|
+
# easier because if you ever change logging frameworks, you don't have to change
|
6
|
+
# all of your app code.
|
7
|
+
#
|
8
|
+
# See http://railsware.com/blog/2014/08/07/rails-logging-into-several-backends/
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'logging'
|
12
|
+
|
13
|
+
log = Logging.logger(STDOUT)
|
14
|
+
log.level = :warn
|
15
|
+
|
16
|
+
Rails.logger.extend(ActiveSupport::Logger.broadcast(log))
|
17
|
+
|
18
|
+
Rails.logger.debug "this debug message will not be output by the logger"
|
19
|
+
Rails.logger.warn "this is your last warning"
|
20
|
+
|
21
|
+
# :startdoc:
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
#
|
3
|
+
# The formatting of log messages is controlled by the layout given to the
|
4
|
+
# appender. By default all appenders use the Basic layout. It's pretty
|
5
|
+
# basic. However, a more sophisticated Pattern layout can be used or one of
|
6
|
+
# the Parseable layouts -- JSON or YAML.
|
7
|
+
#
|
8
|
+
# The available layouts are:
|
9
|
+
#
|
10
|
+
# Logging.layouts.basic
|
11
|
+
# Logging.layouts.pattern
|
12
|
+
# Logging.layouts.json
|
13
|
+
# Logging.layouts.yaml
|
14
|
+
#
|
15
|
+
# After you configure a layout, you can reuse that layout among different
|
16
|
+
# appenders if you so choose. This enables you to have some the style of log
|
17
|
+
# output being sent to multiple destinations.
|
18
|
+
#
|
19
|
+
# We will store a Layout instance in a local variable, and then pass that
|
20
|
+
# instance to each appender.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'logging'
|
24
|
+
|
25
|
+
# create our pattern layout instance
|
26
|
+
layout = Logging.layouts.pattern \
|
27
|
+
:pattern => '[%d] %-5l %c: %m\n',
|
28
|
+
:date_pattern => '%Y-%m-%d %H:%M:%S'
|
29
|
+
|
30
|
+
# only show "info" or higher messages on STDOUT using our layout
|
31
|
+
Logging.appenders.stdout \
|
32
|
+
:level => :info,
|
33
|
+
:layout => layout
|
34
|
+
|
35
|
+
# send all log events to the development log (including debug) using our layout
|
36
|
+
Logging.appenders.rolling_file \
|
37
|
+
'development.log',
|
38
|
+
:age => 'daily',
|
39
|
+
:layout => layout
|
40
|
+
|
41
|
+
log = Logging.logger['Foo::Bar']
|
42
|
+
log.add_appenders 'stdout', 'development.log'
|
43
|
+
log.level = :debug
|
44
|
+
|
45
|
+
log.debug "a very nice little debug message"
|
46
|
+
log.info "things are operating normally"
|
47
|
+
log.warn "this is your last warning"
|
48
|
+
log.error StandardError.new("something went horribly wrong")
|
49
|
+
log.fatal "I Die!"
|
50
|
+
|
51
|
+
# :startdoc:
|
data/lib/logging.rb
CHANGED
@@ -23,6 +23,8 @@ module Logging
|
|
23
23
|
PATH = ::File.expand_path('../..', __FILE__) + ::File::SEPARATOR
|
24
24
|
LEVELS = {}
|
25
25
|
LNAMES = []
|
26
|
+
DEFAULT_CAUSE_DEPTH = 8
|
27
|
+
|
26
28
|
module Plugins; end
|
27
29
|
# :startdoc:
|
28
30
|
|
@@ -95,9 +97,9 @@ module Logging
|
|
95
97
|
layout = ::Logging::Layouts::Pattern.new(l_opts)
|
96
98
|
|
97
99
|
a_opts = Hash.new
|
98
|
-
a_opts[:size] = size if size.
|
100
|
+
a_opts[:size] = size if size.is_a?(Integer)
|
99
101
|
a_opts[:age] = age if age.instance_of?(String)
|
100
|
-
a_opts[:keep] = keep if keep.
|
102
|
+
a_opts[:keep] = keep if keep.is_a?(Integer)
|
101
103
|
a_opts[:filename] = dev if dev.instance_of?(String)
|
102
104
|
a_opts[:layout] = layout
|
103
105
|
a_opts.merge! opts
|
@@ -255,6 +257,9 @@ module Logging
|
|
255
257
|
longest = 'off' if longest.length < 3
|
256
258
|
module_eval "MAX_LEVEL_LENGTH = #{longest.length}", __FILE__, __LINE__
|
257
259
|
|
260
|
+
self.cause_depth = nil unless defined? @cause_depth
|
261
|
+
self.raise_errors = false unless defined? @raise_errors
|
262
|
+
|
258
263
|
initialize_plugins
|
259
264
|
levels.keys
|
260
265
|
end
|
@@ -264,8 +269,8 @@ module Logging
|
|
264
269
|
#
|
265
270
|
# Defines the default _obj_format_ method to use when converting objects
|
266
271
|
# into string representations for logging. _obj_format_ can be one of
|
267
|
-
# <tt>:string</tt>, <tt>:inspect</tt>, or <tt>:yaml</tt>.
|
268
|
-
# formatting commands map to the following object methods
|
272
|
+
# <tt>:string</tt>, <tt>:inspect</tt>, <tt>:json</tt> or <tt>:yaml</tt>.
|
273
|
+
# These formatting commands map to the following object methods
|
269
274
|
#
|
270
275
|
# * :string => to_s
|
271
276
|
# * :inspect => inspect
|
@@ -273,7 +278,7 @@ module Logging
|
|
273
278
|
# * :json => MultiJson.encode(obj)
|
274
279
|
#
|
275
280
|
# An +ArgumentError+ is raised if anything other than +:string+,
|
276
|
-
# +:inspect+, +:yaml+ is passed to this method.
|
281
|
+
# +:inspect+, +:json+ or +:yaml+ is passed to this method.
|
277
282
|
#
|
278
283
|
def format_as( f )
|
279
284
|
f = f.intern if f.instance_of? String
|
@@ -311,6 +316,74 @@ module Logging
|
|
311
316
|
end
|
312
317
|
end
|
313
318
|
|
319
|
+
# Set the default UTC offset used when formatting time values sent to the
|
320
|
+
# appenders. If left unset, the default local time zone will be used for
|
321
|
+
# time values. This method accepts the `utc_offset` format supported by the
|
322
|
+
# `Time#localtime` method in Ruby.
|
323
|
+
#
|
324
|
+
# Passing "UTC" or `0` as the UTC offset will cause all times to be reported
|
325
|
+
# in the UTC timezone.
|
326
|
+
#
|
327
|
+
# Logging.utc_offset = "-07:00" # Mountain Standard Time in North America
|
328
|
+
# Logging.utc_offset = "+01:00" # Central European Time
|
329
|
+
# Logging.utc_offset = "UTC" # UTC
|
330
|
+
# Logging.utc_offset = 0 # UTC
|
331
|
+
#
|
332
|
+
def utc_offset=( value )
|
333
|
+
@utc_offset = case value
|
334
|
+
when nil; nil
|
335
|
+
when "UTC", "GMT", 0; 0
|
336
|
+
else
|
337
|
+
Time.now.localtime(value)
|
338
|
+
value
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
attr_reader :utc_offset
|
343
|
+
|
344
|
+
# Set the default Exception#cause depth used when formatting Exceptions.
|
345
|
+
# This sets the maximum number of nested errors that will be formatted by
|
346
|
+
# the layouts before giving up. This is used to avoid extremely large
|
347
|
+
# outputs.
|
348
|
+
#
|
349
|
+
# Logging.cause_depth = nil # set to the DEFAULT_CAUSE_DEPTH
|
350
|
+
# Logging.cause_depth = 0 # do not show any exception causes
|
351
|
+
# Logging.cause_depth = 1024 # show up to 1024 causes
|
352
|
+
# Logging.cause_depth = -1 # results in the DEFAULT_CAUSE_DEPTH
|
353
|
+
#
|
354
|
+
def cause_depth=( value )
|
355
|
+
if value.nil?
|
356
|
+
@cause_depth = DEFAULT_CAUSE_DEPTH
|
357
|
+
else
|
358
|
+
value = Integer(value)
|
359
|
+
@cause_depth = value < 0 ? DEFAULT_CAUSE_DEPTH : value
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
attr_reader :cause_depth
|
364
|
+
|
365
|
+
# Used to define a `basepath` that will be removed from filenames when
|
366
|
+
# reporting tracing information for log events. Normally you would set this
|
367
|
+
# to the root of your project:
|
368
|
+
#
|
369
|
+
# Logging.basepath = "/home/user/nifty_project"
|
370
|
+
#
|
371
|
+
# Or if you are in a Rails environment:
|
372
|
+
#
|
373
|
+
# Logging.basepath = Rails.root.to_s
|
374
|
+
#
|
375
|
+
# The basepath is expanded to a full path with trailing slashes removed.
|
376
|
+
# This setting will be cleared by a call to `Logging.reset`.
|
377
|
+
def basepath=( path )
|
378
|
+
if path.nil? || path.to_s.empty?
|
379
|
+
@basepath = nil
|
380
|
+
else
|
381
|
+
@basepath = File.expand_path(path)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
attr_reader :basepath
|
386
|
+
|
314
387
|
# Returns the library path for the module. If any arguments are given,
|
315
388
|
# they will be joined to the end of the library path using
|
316
389
|
# <tt>File.join</tt>.
|
@@ -405,7 +478,7 @@ module Logging
|
|
405
478
|
# to false. It uses its own appender to send messages to stderr.
|
406
479
|
#
|
407
480
|
def show_configuration( io = STDOUT, logger = 'root', indent = 0 )
|
408
|
-
logger = ::Logging::Logger[logger] unless ::Logging::Logger
|
481
|
+
logger = ::Logging::Logger[logger] unless logger.is_a?(::Logging::Logger)
|
409
482
|
|
410
483
|
io << logger._dump_configuration(indent)
|
411
484
|
|
@@ -418,6 +491,21 @@ module Logging
|
|
418
491
|
io
|
419
492
|
end
|
420
493
|
|
494
|
+
# Raise an exception when an error is encountered while logging, be it with
|
495
|
+
# a backing store, formatter, or anything else. You probably wouldn't want
|
496
|
+
# to enable this outside of test.
|
497
|
+
#
|
498
|
+
# Not that only one error will ever be raised per logging backend, as
|
499
|
+
# backends that raise errors on write will be set to :off.
|
500
|
+
def raise_errors=(boolean)
|
501
|
+
@raise_errors = boolean
|
502
|
+
end
|
503
|
+
|
504
|
+
# Whether or not we should raise errors when writing logs.
|
505
|
+
def raise_errors?
|
506
|
+
@raise_errors
|
507
|
+
end
|
508
|
+
|
421
509
|
# :stopdoc:
|
422
510
|
# Convert the given level into a canonical form - a lowercase string.
|
423
511
|
def levelify( level )
|
@@ -446,7 +534,7 @@ module Logging
|
|
446
534
|
# exception will be raised again.
|
447
535
|
def log_internal_error( err )
|
448
536
|
log_internal(-2) { err }
|
449
|
-
raise err if
|
537
|
+
raise err if ::Logging.raise_errors?
|
450
538
|
end
|
451
539
|
|
452
540
|
# Close all appenders
|
@@ -466,8 +554,11 @@ module Logging
|
|
466
554
|
LEVELS.clear
|
467
555
|
LNAMES.clear
|
468
556
|
remove_instance_variable :@backtrace if defined? @backtrace
|
557
|
+
remove_instance_variable :@basepath if defined? @basepath
|
469
558
|
remove_const :MAX_LEVEL_LENGTH if const_defined? :MAX_LEVEL_LENGTH
|
470
559
|
remove_const :OBJ_FORMAT if const_defined? :OBJ_FORMAT
|
560
|
+
self.utc_offset = nil
|
561
|
+
self.cause_depth = nil
|
471
562
|
self
|
472
563
|
end
|
473
564
|
|
@@ -494,8 +585,7 @@ module Logging
|
|
494
585
|
require libpath('logging/diagnostic_context')
|
495
586
|
|
496
587
|
require libpath('logging/rails_compat')
|
497
|
-
end
|
498
|
-
|
588
|
+
end
|
499
589
|
|
500
590
|
# This finalizer will close all the appenders that exist in the system.
|
501
591
|
# This is needed for closing IO streams and connections to the syslog server
|