logging 1.8.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/History.txt +20 -0
  4. data/README.md +159 -0
  5. data/Rakefile +9 -5
  6. data/examples/appenders.rb +0 -4
  7. data/examples/layouts.rb +1 -8
  8. data/examples/names.rb +4 -4
  9. data/lib/logging.rb +24 -76
  10. data/lib/logging/appender.rb +71 -16
  11. data/lib/logging/appenders.rb +0 -2
  12. data/lib/logging/appenders/buffering.rb +32 -16
  13. data/lib/logging/appenders/file.rb +2 -2
  14. data/lib/logging/appenders/io.rb +1 -1
  15. data/lib/logging/appenders/rolling_file.rb +228 -165
  16. data/lib/logging/appenders/string_io.rb +1 -1
  17. data/lib/logging/appenders/syslog.rb +4 -4
  18. data/lib/logging/color_scheme.rb +20 -3
  19. data/lib/logging/diagnostic_context.rb +142 -17
  20. data/lib/logging/filter.rb +18 -0
  21. data/lib/logging/filters.rb +4 -0
  22. data/lib/logging/filters/level.rb +29 -0
  23. data/lib/logging/layout.rb +2 -2
  24. data/lib/logging/layouts/parseable.rb +5 -2
  25. data/lib/logging/layouts/pattern.rb +309 -168
  26. data/lib/logging/log_event.rb +5 -5
  27. data/lib/logging/logger.rb +55 -68
  28. data/lib/logging/repository.rb +24 -39
  29. data/lib/logging/root_logger.rb +1 -1
  30. data/lib/logging/utils.rb +4 -65
  31. data/lib/logging/version.rb +8 -0
  32. data/lib/rspec/logging_helper.rb +3 -3
  33. data/logging.gemspec +46 -0
  34. data/test/appenders/test_buffered_io.rb +29 -0
  35. data/test/appenders/test_file.rb +2 -2
  36. data/test/appenders/test_rolling_file.rb +62 -1
  37. data/test/layouts/test_color_pattern.rb +1 -1
  38. data/test/layouts/test_json.rb +3 -0
  39. data/test/layouts/test_pattern.rb +6 -2
  40. data/test/layouts/test_yaml.rb +4 -1
  41. data/test/test_appender.rb +56 -0
  42. data/test/test_filter.rb +33 -0
  43. data/test/test_layout.rb +4 -8
  44. data/test/test_log_event.rb +3 -3
  45. data/test/test_logger.rb +81 -57
  46. data/test/test_logging.rb +0 -59
  47. data/test/test_mapped_diagnostic_context.rb +49 -1
  48. data/test/test_nested_diagnostic_context.rb +16 -1
  49. data/test/test_repository.rb +24 -32
  50. data/test/test_utils.rb +14 -50
  51. metadata +35 -53
  52. data/README.rdoc +0 -143
  53. data/data/bad_logging_1.rb +0 -13
  54. data/data/bad_logging_2.rb +0 -21
  55. data/data/logging.rb +0 -42
  56. data/data/logging.yaml +0 -63
  57. data/data/simple_logging.rb +0 -13
  58. data/examples/consolidation.rb +0 -83
  59. data/lib/logging/appenders/email.rb +0 -178
  60. data/lib/logging/appenders/growl.rb +0 -200
  61. data/lib/logging/config/configurator.rb +0 -187
  62. data/lib/logging/config/yaml_configurator.rb +0 -190
  63. data/lib/logging/stats.rb +0 -277
  64. data/test/appenders/test_email.rb +0 -170
  65. data/test/appenders/test_growl.rb +0 -138
  66. data/test/config/test_configurator.rb +0 -69
  67. data/test/config/test_yaml_configurator.rb +0 -39
  68. data/test/test_consolidate.rb +0 -45
  69. data/test/test_stats.rb +0 -273
  70. data/version.txt +0 -1
@@ -1,69 +0,0 @@
1
-
2
- require File.expand_path('../setup', File.dirname(__FILE__))
3
-
4
- module TestLogging
5
- module TestConfig
6
-
7
- class TestConfigurator < Test::Unit::TestCase
8
- include LoggingTestCase
9
-
10
- def test_configuration
11
- begin
12
- load Logging.path(%w[data logging.rb])
13
- rescue Exception => err
14
- flunk err.inspect
15
- end
16
-
17
- levels = {
18
- 'deb' => 0,
19
- 'inf' => 1,
20
- 'prt' => 2,
21
- 'wrn' => 3,
22
- 'err' => 4,
23
- 'fat' => 5
24
- }
25
- assert_equal levels, Logging::LEVELS
26
- assert_equal :inspect, Logging::OBJ_FORMAT
27
-
28
- hash = Logging::Repository.instance.instance_variable_get(:@h)
29
- assert hash.has_key?('A::B::C')
30
- assert hash.has_key?('yourlogger')
31
- end
32
-
33
- def test_simple_configuration
34
- begin
35
- load Logging.path(%w[data simple_logging.rb])
36
- rescue Exception => err
37
- flunk err.inspect
38
- end
39
-
40
- levels = {
41
- 'debug' => 0,
42
- 'info' => 1,
43
- 'warn' => 2,
44
- 'error' => 3,
45
- 'fatal' => 4
46
- }
47
- assert_equal levels, Logging::LEVELS
48
- assert_equal false, Logging.const_defined?('OBJ_FORMAT')
49
-
50
- root = Logging::Logger.root
51
- assert_equal 1, root.level
52
- end
53
-
54
- def test_bad_appender_configuration
55
- assert_raise(Logging::Config::Configurator::Error) {
56
- load Logging.path(%w[data bad_logging_1.rb])
57
- }
58
- end
59
-
60
- def test_bad_layout_configuration
61
- assert_raise(Logging::Config::Configurator::Error) {
62
- load Logging.path(%w[data bad_logging_2.rb])
63
- }
64
- end
65
- end
66
-
67
- end # module TestConfig
68
- end # module TestLogging
69
-
@@ -1,39 +0,0 @@
1
-
2
- require File.expand_path('../setup', File.dirname(__FILE__))
3
-
4
- module TestLogging
5
- module TestConfig
6
-
7
- class TestYamlConfigurator < Test::Unit::TestCase
8
- include LoggingTestCase
9
-
10
- def test_class_load
11
- assert_raise(::Logging::Config::YamlConfigurator::Error) {
12
- ::Logging::Config::YamlConfigurator.load(Object.new)
13
- }
14
-
15
- begin
16
- fd = File.open('data/logging.yaml','r')
17
- assert_nothing_raised {
18
- ::Logging::Config::YamlConfigurator.load(fd)
19
- }
20
- ensure
21
- fd.close
22
- end
23
- end
24
-
25
- def test_initialize
26
- io = StringIO.new
27
- io << YAML.dump({:one => 1, :two => 2, :three => 3})
28
- io.seek 0
29
-
30
- assert_raise(::Logging::Config::YamlConfigurator::Error) {
31
- ::Logging::Config::YamlConfigurator.new(io, :meh)
32
- }
33
- end
34
-
35
- end # class TestYamlConfigurator
36
-
37
- end # module TestConfig
38
- end # module TestLogging
39
-
@@ -1,45 +0,0 @@
1
-
2
- require File.expand_path('setup', File.dirname(__FILE__))
3
-
4
- module TestLogging
5
-
6
- class TestConsolidate < Test::Unit::TestCase
7
- include LoggingTestCase
8
-
9
- def test_root
10
- Logging.consolidate :root
11
- root = Logging.logger.root
12
-
13
- assert_same root, Logging.logger['Foo']
14
- assert_same root, Logging.logger['Foo::Bar']
15
- assert_same root, Logging.logger[Array]
16
- end
17
-
18
- def test_foo
19
- Logging.consolidate 'Foo'
20
- logger = Logging.logger['Foo::Bar::Baz']
21
-
22
- assert_same Logging.logger['Foo'], logger
23
- assert_not_same Logging.logger.root, logger
24
- end
25
-
26
- def test_many
27
- Logging.consolidate 'Foo', 'root', 'Foo::Bar::Baz'
28
-
29
- root = Logging.logger.root
30
- foo = Logging.logger['Foo']
31
- fbb = Logging.logger['Foo::Bar::Baz']
32
-
33
- assert_not_same root, foo
34
- assert_not_same root, fbb
35
- assert_not_same foo, fbb
36
-
37
- assert_same root, Logging.logger[Hash]
38
- assert_same root, Logging.logger['ActiveRecord::Base']
39
- assert_same foo, Logging.logger['Foo::Bar']
40
- assert_same fbb, Logging.logger['Foo::Bar::Baz::Buz']
41
- end
42
-
43
- end # class TestConsolidate
44
- end # module TestLogging
45
-
@@ -1,273 +0,0 @@
1
-
2
- require File.expand_path('setup', File.dirname(__FILE__))
3
-
4
- module TestLogging
5
- module TestStats
6
-
7
- class TestSampler < Test::Unit::TestCase
8
- include LoggingTestCase
9
-
10
- def setup
11
- super
12
- @sampler = ::Logging::Stats::Sampler.new('test')
13
- end
14
-
15
- def test_reset
16
- (1..10).each {|n| @sampler.sample n}
17
-
18
- assert_equal 55, @sampler.sum
19
- assert_equal 385, @sampler.sumsq
20
- assert_equal 10, @sampler.num
21
- assert_equal 1, @sampler.min
22
- assert_equal 10, @sampler.max
23
- assert_equal 10, @sampler.last
24
-
25
- @sampler.reset
26
-
27
- assert_equal 0, @sampler.sum
28
- assert_equal 0, @sampler.sumsq
29
- assert_equal 0, @sampler.num
30
- assert_equal 0, @sampler.min
31
- assert_equal 0, @sampler.max
32
- assert_nil @sampler.last
33
- end
34
-
35
- def test_coalesce
36
- other = ::Logging::Stats::Sampler.new('other')
37
- (1..5).each {|n| other.sample n}
38
- (6..10).each {|n| @sampler.sample n}
39
-
40
- assert_equal 5, @sampler.num
41
-
42
- @sampler.coalesce other
43
-
44
- assert_equal 55, @sampler.sum
45
- assert_equal 385, @sampler.sumsq
46
- assert_equal 10, @sampler.num
47
- assert_equal 1, @sampler.min
48
- assert_equal 10, @sampler.max
49
- assert_equal 5, @sampler.last
50
-
51
- @sampler.coalesce ::Logging::Stats::Sampler.new('tmp')
52
-
53
- assert_equal 55, @sampler.sum
54
- assert_equal 385, @sampler.sumsq
55
- assert_equal 10, @sampler.num
56
- assert_equal 1, @sampler.min
57
- assert_equal 10, @sampler.max
58
- assert_equal 5, @sampler.last
59
- end
60
-
61
- def test_sample
62
- @sampler.sample 1
63
-
64
- assert_equal 1, @sampler.sum
65
- assert_equal 1, @sampler.sumsq
66
- assert_equal 1, @sampler.num
67
- assert_equal 1, @sampler.min
68
- assert_equal 1, @sampler.max
69
- assert_equal 1, @sampler.last
70
-
71
- @sampler.sample 2
72
-
73
- assert_equal 3, @sampler.sum
74
- assert_equal 5, @sampler.sumsq
75
- assert_equal 2, @sampler.num
76
- assert_equal 1, @sampler.min
77
- assert_equal 2, @sampler.max
78
- assert_equal 2, @sampler.last
79
- end
80
-
81
- def test_to_s
82
- (1..10).each {|n| @sampler.sample n}
83
- assert_equal(
84
- "[test]: SUM=55.000000, SUMSQ=385.000000, NUM=10, MEAN=5.500000, SD=3.027650, MIN=1.000000, MAX=10.000000",
85
- @sampler.to_s
86
- )
87
- end
88
-
89
- def test_to_a
90
- (1..10).each {|n| @sampler.sample n}
91
- assert_equal(
92
- ['test', 55, 385, 10, 5.5, @sampler.sd, 1, 10],
93
- @sampler.to_a
94
- )
95
- end
96
-
97
- def test_to_hash
98
- (1..10).each {|n| @sampler.sample n}
99
- assert_equal(
100
- {:name => 'test', :sum => 55, :sumsq => 385, :num => 10, :mean => 5.5, :sd => @sampler.sd, :min => 1, :max => 10},
101
- @sampler.to_hash
102
- )
103
- end
104
-
105
- def test_mean
106
- assert_equal 0, @sampler.mean
107
-
108
- @sampler.sample 10
109
- assert_equal 10, @sampler.mean
110
-
111
- @sampler.sample 20
112
- assert_equal 15, @sampler.mean
113
- end
114
-
115
- def test_sd
116
- assert_equal 0, @sampler.sd
117
-
118
- @sampler.sample 1
119
- assert_equal 0, @sampler.sd
120
-
121
- @sampler.sample 2
122
- assert_in_delta 0.707106781186548, @sampler.sd, 1e-10
123
-
124
- @sampler.sample 3
125
- assert_in_delta 1.0, @sampler.sd, 1e-10
126
-
127
- @sampler.sample 4
128
- assert_in_delta 1.29099444873581, @sampler.sd, 1e-10
129
- end
130
-
131
- def test_mark_and_tick
132
- 10.times do
133
- @sampler.mark
134
- sleep 0.01
135
- @sampler.tick
136
- end
137
-
138
- assert_equal 10, @sampler.num
139
- assert_in_delta 0.01, @sampler.mean, 1e-3
140
- end
141
- end # class TestSampler
142
-
143
- class TestTracker < Test::Unit::TestCase
144
- include LoggingTestCase
145
-
146
- def setup
147
- super
148
- @tracker = ::Logging::Stats::Tracker.new
149
- @stats = @tracker.stats
150
- end
151
-
152
- def test_coalesce
153
- 1.times {|n| @tracker.sample('foo', n)}
154
- 2.times {|n| @tracker.sample('bar', n)}
155
- 3.times {|n| @tracker.sample('baz', n)}
156
-
157
- assert_equal %w[bar baz foo], @stats.keys.sort
158
- assert_equal 1, @stats['foo'].num
159
- assert_equal 2, @stats['bar'].num
160
- assert_equal 3, @stats['baz'].num
161
-
162
- # when other is empty, nothing should change in our tracker
163
- other = ::Logging::Stats::Tracker.new
164
- @tracker.coalesce other
165
-
166
- assert_equal %w[bar baz foo], @stats.keys.sort
167
- assert_equal 1, @stats['foo'].num
168
- assert_equal 2, @stats['bar'].num
169
- assert_equal 3, @stats['baz'].num
170
-
171
- # now add some samples to other
172
- 4.times {|n| other.sample('buz', n)}
173
- 5.times {|n| other.sample('bar', n)}
174
- @tracker.coalesce other
175
-
176
- assert_equal %w[bar baz buz foo], @stats.keys.sort
177
- assert_equal 1, @stats['foo'].num
178
- assert_equal 7, @stats['bar'].num
179
- assert_equal 3, @stats['baz'].num
180
- assert_equal 4, @stats['buz'].num
181
- end
182
-
183
- def test_mark
184
- assert @stats.empty?
185
- @tracker.mark 'foo'
186
- assert !@stats.empty?
187
-
188
- sampler = @stats['foo']
189
- assert_equal 0, sampler.num
190
- end
191
-
192
- def test_tick
193
- assert @stats.empty?
194
- @tracker.tick 'foo'
195
- assert !@stats.empty?
196
-
197
- sampler = @stats['foo']
198
- assert_equal 1, sampler.num
199
- end
200
-
201
- def test_sample
202
- assert @stats.empty?
203
- @tracker.sample 'foo', 1
204
- assert !@stats.empty?
205
-
206
- sampler = @stats['foo']
207
- assert_equal 1, sampler.num
208
- assert_equal 1, sampler.last
209
-
210
- @tracker.sample 'foo', 2
211
- assert_equal 2, sampler.num
212
- assert_equal 2, sampler.last
213
- assert_equal 3, sampler.sum
214
- end
215
-
216
- def test_time
217
- assert @stats.empty?
218
- @tracker.time('foo') {sleep 0.05}
219
- assert !@stats.empty?
220
-
221
- sampler = @stats['foo']
222
- assert_equal 1, sampler.num
223
- assert_in_delta 0.05, sampler.sum, 1e-2
224
-
225
- @tracker.time('foo') {sleep 0.05}
226
- assert_equal 2, sampler.num
227
- assert_in_delta 0.10, sampler.sum, 1e-2
228
-
229
- assert_raise(RuntimeError) do
230
- @tracker.time('foo') {raise 'Uh Oh!'}
231
- end
232
- assert_equal 3, sampler.num
233
- end
234
-
235
- def test_reset
236
- 1.times {|n| @tracker.sample('foo', n)}
237
- 2.times {|n| @tracker.sample('bar', n)}
238
- 3.times {|n| @tracker.sample('baz', n)}
239
-
240
- assert_equal 1, @stats['foo'].num
241
- assert_equal 2, @stats['bar'].num
242
- assert_equal 3, @stats['baz'].num
243
-
244
- @tracker.reset
245
-
246
- assert_equal 0, @stats['foo'].num
247
- assert_equal 0, @stats['bar'].num
248
- assert_equal 0, @stats['baz'].num
249
- end
250
-
251
- def test_reentrant_synchronization
252
- assert_nothing_raised do
253
- @tracker.sync {
254
- @tracker.sample('foo', Math::PI)
255
- @tracker.reset
256
- }
257
- end
258
- end
259
-
260
- def test_periodically_run
261
- @tracker.periodically_run(0.1) {
262
- @tracker.tick 'foo'
263
- }
264
- sleep 0.5
265
- @tracker.stop
266
-
267
- assert(@stats['foo'].num > 1)
268
- end
269
- end # class TestTracker
270
-
271
- end # module TestStats
272
- end # module TestLogging
273
-
@@ -1 +0,0 @@
1
- 1.8.2