TwP-logging 0.9.7

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.
Files changed (54) hide show
  1. data/History.txt +169 -0
  2. data/README.rdoc +102 -0
  3. data/Rakefile +42 -0
  4. data/data/bad_logging_1.rb +13 -0
  5. data/data/bad_logging_2.rb +21 -0
  6. data/data/logging.rb +42 -0
  7. data/data/logging.yaml +63 -0
  8. data/data/simple_logging.rb +13 -0
  9. data/lib/logging.rb +408 -0
  10. data/lib/logging/appender.rb +303 -0
  11. data/lib/logging/appenders/buffering.rb +167 -0
  12. data/lib/logging/appenders/console.rb +62 -0
  13. data/lib/logging/appenders/email.rb +75 -0
  14. data/lib/logging/appenders/file.rb +54 -0
  15. data/lib/logging/appenders/growl.rb +197 -0
  16. data/lib/logging/appenders/io.rb +69 -0
  17. data/lib/logging/appenders/rolling_file.rb +291 -0
  18. data/lib/logging/appenders/syslog.rb +201 -0
  19. data/lib/logging/config/configurator.rb +190 -0
  20. data/lib/logging/config/yaml_configurator.rb +195 -0
  21. data/lib/logging/layout.rb +119 -0
  22. data/lib/logging/layouts/basic.rb +34 -0
  23. data/lib/logging/layouts/pattern.rb +296 -0
  24. data/lib/logging/log_event.rb +51 -0
  25. data/lib/logging/logger.rb +490 -0
  26. data/lib/logging/repository.rb +172 -0
  27. data/lib/logging/root_logger.rb +61 -0
  28. data/lib/logging/stats.rb +278 -0
  29. data/lib/logging/utils.rb +130 -0
  30. data/logging.gemspec +41 -0
  31. data/test/appenders/test_buffered_io.rb +183 -0
  32. data/test/appenders/test_console.rb +66 -0
  33. data/test/appenders/test_email.rb +171 -0
  34. data/test/appenders/test_file.rb +93 -0
  35. data/test/appenders/test_growl.rb +128 -0
  36. data/test/appenders/test_io.rb +142 -0
  37. data/test/appenders/test_rolling_file.rb +207 -0
  38. data/test/appenders/test_syslog.rb +194 -0
  39. data/test/benchmark.rb +87 -0
  40. data/test/config/test_configurator.rb +70 -0
  41. data/test/config/test_yaml_configurator.rb +40 -0
  42. data/test/layouts/test_basic.rb +43 -0
  43. data/test/layouts/test_pattern.rb +177 -0
  44. data/test/setup.rb +74 -0
  45. data/test/test_appender.rb +166 -0
  46. data/test/test_layout.rb +110 -0
  47. data/test/test_log_event.rb +80 -0
  48. data/test/test_logger.rb +734 -0
  49. data/test/test_logging.rb +267 -0
  50. data/test/test_repository.rb +126 -0
  51. data/test/test_root_logger.rb +81 -0
  52. data/test/test_stats.rb +274 -0
  53. data/test/test_utils.rb +116 -0
  54. metadata +156 -0
@@ -0,0 +1,274 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[setup])
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
+
274
+ # EOF
@@ -0,0 +1,116 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[setup])
3
+
4
+ module TestLogging
5
+
6
+ class TestUtils < Test::Unit::TestCase
7
+
8
+ def test_hash_getopt
9
+ opts = {
10
+ :foo => 'foo_value',
11
+ 'bar' => 'bar_value',
12
+ 'one' => '1',
13
+ :two => '2',
14
+ :three => 3.0
15
+ }
16
+
17
+ assert_equal('foo_value', opts.getopt(:foo))
18
+ assert_equal('foo_value', opts.getopt('foo'))
19
+ assert_equal(:foo_value, opts.getopt(:foo, :as => Symbol))
20
+
21
+ assert_equal('bar_value', opts.getopt(:bar))
22
+ assert_equal('bar_value', opts.getopt('bar'))
23
+
24
+ assert_equal('1', opts.getopt(:one))
25
+ assert_equal(1, opts.getopt('one', :as => Integer))
26
+ assert_instance_of(Float, opts.getopt('one', :as => Float))
27
+
28
+ assert_equal('2', opts.getopt(:two))
29
+ assert_equal(['2'], opts.getopt(:two, :as => Array))
30
+
31
+ assert_equal(3.0, opts.getopt(:three))
32
+ assert_equal('3.0', opts.getopt('three', :as => String))
33
+
34
+ assert_equal(nil, opts.getopt(:baz))
35
+ assert_equal('default', opts.getopt('baz', 'default'))
36
+ assert_equal(:default, opts.getopt(:key, 'default', :as => Symbol))
37
+ assert_equal(['default'], opts.getopt('key', 'default', :as => Array))
38
+
39
+ assert_equal(3.0, opts.getopt(:three, :as => Object))
40
+
41
+ assert_nil opts.getopt(:key, :as => Symbol)
42
+ end
43
+
44
+ def test_string_reduce
45
+ str = 'this is the foobar string'
46
+ len = str.length
47
+
48
+ r = str.reduce(len + 1)
49
+ assert_same str, r
50
+
51
+ r = str.reduce(len)
52
+ assert_same str, r
53
+
54
+ r = str.reduce(len - 1)
55
+ assert_equal 'this is the...bar string', r
56
+
57
+ r = str.reduce(len - 10)
58
+ assert_equal 'this i...string', r
59
+
60
+ r = str.reduce(4)
61
+ assert_equal 't...', r
62
+
63
+ r = str.reduce(3)
64
+ assert_equal '...', r
65
+
66
+ r = str.reduce(0)
67
+ assert_equal '...', r
68
+
69
+ assert_raises(ArgumentError) { str.reduce(-1) }
70
+
71
+ r = str.reduce(len - 1, '##')
72
+ assert_equal 'this is the##obar string', r
73
+
74
+ r = str.reduce(len - 10, '##')
75
+ assert_equal 'this is##string', r
76
+
77
+ r = str.reduce(4, '##')
78
+ assert_equal 't##g', r
79
+
80
+ r = str.reduce(3, '##')
81
+ assert_equal 't##', r
82
+
83
+ r = str.reduce(0, '##')
84
+ assert_equal '##', r
85
+ end
86
+
87
+ def test_logger_name
88
+ assert_equal 'Array', Array.logger_name
89
+
90
+ # some lines are commented out for compatibility with ruby 1.9
91
+
92
+ c = Class.new(Array)
93
+ # assert_equal '', c.name
94
+ assert_equal 'Array', c.logger_name
95
+
96
+ meta = class << Array; self; end
97
+ # assert_equal '', meta.name
98
+ assert_equal 'Array', meta.logger_name
99
+
100
+ m = Module.new
101
+ # assert_equal '', m.name
102
+ assert_equal 'anonymous', m.logger_name
103
+
104
+ c = Class.new(::Logging::Logger)
105
+ # assert_equal '', c.name
106
+ assert_equal 'Logging::Logger', c.logger_name
107
+
108
+ meta = class << ::Logging::Logger; self; end
109
+ # assert_equal '', meta.name
110
+ assert_equal 'Logging::Logger', meta.logger_name
111
+ end
112
+
113
+ end # class TestUtils
114
+ end # module TestLogging
115
+
116
+ # EOF
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TwP-logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.7
5
+ platform: ruby
6
+ authors:
7
+ - Tim Pease
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-23 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: flexmock
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: lockfile
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bones
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.4.0
44
+ version:
45
+ description: Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.
46
+ email: tim.pease@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - README.rdoc
54
+ files:
55
+ - History.txt
56
+ - README.rdoc
57
+ - Rakefile
58
+ - data/bad_logging_1.rb
59
+ - data/bad_logging_2.rb
60
+ - data/logging.rb
61
+ - data/logging.yaml
62
+ - data/simple_logging.rb
63
+ - lib/logging.rb
64
+ - lib/logging/appender.rb
65
+ - lib/logging/appenders/buffering.rb
66
+ - lib/logging/appenders/console.rb
67
+ - lib/logging/appenders/email.rb
68
+ - lib/logging/appenders/file.rb
69
+ - lib/logging/appenders/growl.rb
70
+ - lib/logging/appenders/io.rb
71
+ - lib/logging/appenders/rolling_file.rb
72
+ - lib/logging/appenders/syslog.rb
73
+ - lib/logging/config/configurator.rb
74
+ - lib/logging/config/yaml_configurator.rb
75
+ - lib/logging/layout.rb
76
+ - lib/logging/layouts/basic.rb
77
+ - lib/logging/layouts/pattern.rb
78
+ - lib/logging/log_event.rb
79
+ - lib/logging/logger.rb
80
+ - lib/logging/repository.rb
81
+ - lib/logging/root_logger.rb
82
+ - lib/logging/stats.rb
83
+ - lib/logging/utils.rb
84
+ - logging.gemspec
85
+ - test/appenders/test_buffered_io.rb
86
+ - test/appenders/test_console.rb
87
+ - test/appenders/test_email.rb
88
+ - test/appenders/test_file.rb
89
+ - test/appenders/test_growl.rb
90
+ - test/appenders/test_io.rb
91
+ - test/appenders/test_rolling_file.rb
92
+ - test/appenders/test_syslog.rb
93
+ - test/benchmark.rb
94
+ - test/config/test_configurator.rb
95
+ - test/config/test_yaml_configurator.rb
96
+ - test/layouts/test_basic.rb
97
+ - test/layouts/test_pattern.rb
98
+ - test/setup.rb
99
+ - test/test_appender.rb
100
+ - test/test_layout.rb
101
+ - test/test_log_event.rb
102
+ - test/test_logger.rb
103
+ - test/test_logging.rb
104
+ - test/test_repository.rb
105
+ - test/test_root_logger.rb
106
+ - test/test_stats.rb
107
+ - test/test_utils.rb
108
+ has_rdoc: true
109
+ homepage: http://logging.rubyforge.org/
110
+ post_install_message:
111
+ rdoc_options:
112
+ - --main
113
+ - README.rdoc
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: "0"
127
+ version:
128
+ requirements: []
129
+
130
+ rubyforge_project: logging
131
+ rubygems_version: 1.2.0
132
+ signing_key:
133
+ specification_version: 2
134
+ summary: A flexible and extendable logging library for Ruby
135
+ test_files:
136
+ - test/appenders/test_buffered_io.rb
137
+ - test/appenders/test_console.rb
138
+ - test/appenders/test_email.rb
139
+ - test/appenders/test_file.rb
140
+ - test/appenders/test_growl.rb
141
+ - test/appenders/test_io.rb
142
+ - test/appenders/test_rolling_file.rb
143
+ - test/appenders/test_syslog.rb
144
+ - test/config/test_configurator.rb
145
+ - test/config/test_yaml_configurator.rb
146
+ - test/layouts/test_basic.rb
147
+ - test/layouts/test_pattern.rb
148
+ - test/test_appender.rb
149
+ - test/test_layout.rb
150
+ - test/test_log_event.rb
151
+ - test/test_logger.rb
152
+ - test/test_logging.rb
153
+ - test/test_repository.rb
154
+ - test/test_root_logger.rb
155
+ - test/test_stats.rb
156
+ - test/test_utils.rb