logging 1.7.2 → 1.8.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.
@@ -191,6 +191,41 @@ module TestLayouts
191
191
  assert_equal 'message{42}', @layout.format(event)
192
192
  end
193
193
 
194
+ def test_pattern_mdc
195
+ @layout.pattern = 'S:%X{X-Session} C:%X{Cookie}'
196
+ event = Logging::LogEvent.new('TestLogger', @levels['info'], 'log message', false)
197
+
198
+ Logging.mdc['X-Session'] = '123abc'
199
+ Logging.mdc['Cookie'] = 'monster'
200
+ assert_equal 'S:123abc C:monster', @layout.format(event)
201
+
202
+ Logging.mdc.delete 'Cookie'
203
+ assert_equal 'S:123abc C:', @layout.format(event)
204
+
205
+ Logging.mdc.delete 'X-Session'
206
+ assert_equal 'S: C:', @layout.format(event)
207
+ end
208
+
209
+ def test_pattern_mdc_requires_key_name
210
+ assert_raise(ArgumentError) { @layout.pattern = '%X' }
211
+ assert_raise(ArgumentError) { @layout.pattern = '%X{}' }
212
+ end
213
+
214
+ def test_pattern_ndc
215
+ @layout.pattern = '%x'
216
+ event = Logging::LogEvent.new('TestLogger', @levels['info'], 'log message', false)
217
+
218
+ Logging.ndc << 'context a'
219
+ Logging.ndc << 'context b'
220
+ assert_equal 'context a context b', @layout.format(event)
221
+
222
+ @layout.pattern = '%x{, }'
223
+ assert_equal 'context a, context b', @layout.format(event)
224
+
225
+ Logging.ndc.pop
226
+ assert_equal 'context a', @layout.format(event)
227
+ end
228
+
194
229
  end # TestBasic
195
230
  end # TestLayouts
196
231
  end # TestLogging
@@ -11,7 +11,7 @@ module TestLayouts
11
11
  super
12
12
  @layout = Logging.layouts.yaml({})
13
13
  @levels = Logging::LEVELS
14
- @date_fmt = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{6,9} (Z|[+-]\d{2}:\d{2})'
14
+ @date_fmt = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}(Z|[+-]\d{2}:\d{2})'
15
15
  Thread.current[:name] = nil
16
16
  end
17
17
 
@@ -27,7 +27,7 @@ module TestLayouts
27
27
  assert_yaml_match h, @layout.format(event)
28
28
 
29
29
  event.data = [1, 2, 3, 4]
30
- h['message'] = "<Array> #{[1,2,3,4]}"
30
+ h['message'] = [1,2,3,4]
31
31
  assert_yaml_match h, @layout.format(event)
32
32
 
33
33
  event.level = @levels['debug']
@@ -41,7 +41,7 @@ module TestLayouts
41
41
  event.data = Exception.new
42
42
  h['level'] = 'FATAL'
43
43
  h['logger'] = 'Test'
44
- h['message'] = '<Exception> Exception'
44
+ h['message'] = {:class => 'Exception', :message => 'Exception'}
45
45
  assert_yaml_match h, @layout.format(event)
46
46
  end
47
47
 
@@ -55,7 +55,7 @@ module TestLayouts
55
55
 
56
56
  @layout.items = %w[timestamp]
57
57
  assert_equal %w[timestamp], @layout.items
58
- assert_match %r/\A--- ?\ntimestamp: '?#@date_fmt'?\n/, @layout.format(event)
58
+ assert_match %r/\A--- ?\ntimestamp: ["']#@date_fmt["']\n/, @layout.format(event)
59
59
 
60
60
  # 'foo' is not a recognized item
61
61
  assert_raise(ArgumentError) {
@@ -101,14 +101,57 @@ module TestLayouts
101
101
  assert_match %r/\A--- ?\nthread: \n/, @layout.format(event)
102
102
  Thread.current[:name] = "Main"
103
103
  assert_match %r/\A--- ?\nthread: Main\n/, @layout.format(event)
104
+
105
+ @layout.items = %w[mdc]
106
+ assert_match %r/\A--- ?\nmdc: \{\}\n/, @layout.format(event)
107
+
108
+ @layout.items = %w[ndc]
109
+ assert_match %r/\A--- ?\nndc: \[\]\n/, @layout.format(event)
110
+ end
111
+
112
+ def test_mdc_output
113
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
114
+ 'log message', false)
115
+ Logging.mdc['X-Session'] = '123abc'
116
+ Logging.mdc['Cookie'] = 'monster'
117
+
118
+ @layout.items = %w[timestamp level logger message mdc]
119
+
120
+ format = @layout.format(event)
121
+ assert_match %r/\nmdc: ?(?:\n (?:X-Session: 123abc|Cookie: monster)\n?){2}/, format
122
+
123
+ Logging.mdc.delete 'Cookie'
124
+ format = @layout.format(event)
125
+ assert_match %r/\nmdc: ?\n X-Session: 123abc\n/, format
126
+ end
127
+
128
+ def test_ndc_output
129
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
130
+ 'log message', false)
131
+ Logging.ndc << 'context a'
132
+ Logging.ndc << 'context b'
133
+
134
+ @layout.items = %w[timestamp level logger message ndc]
135
+
136
+ format = @layout.format(event)
137
+ assert_match %r/\nndc: ?\n\s*- context a\n\s*- context b\n/, format
138
+
139
+ Logging.ndc.pop
140
+ format = @layout.format(event)
141
+ assert_match %r/\nndc: ?\n\s*- context a\n/, format
142
+
143
+ Logging.ndc.pop
144
+ format = @layout.format(event)
145
+ assert_match %r/\nndc: \[\]\n/, format
104
146
  end
105
147
 
106
- private
148
+ private
107
149
 
108
150
  def assert_yaml_match( expected, actual )
109
151
  actual = YAML.load(actual)
110
152
 
111
- assert_instance_of Time, actual['timestamp']
153
+ assert_instance_of String, actual['timestamp']
154
+ assert_instance_of Time, Time.parse(actual['timestamp'])
112
155
  assert_equal expected['level'], actual['level']
113
156
  assert_equal expected['logger'], actual['logger']
114
157
  assert_equal expected['message'], actual['message']
@@ -26,6 +26,9 @@ module TestLogging
26
26
  @layout = ::Logging::Layout.new :format_as => :inspect
27
27
  assert_equal :inspect, obj_format[@layout]
28
28
 
29
+ @layout = ::Logging::Layout.new 'format_as' => :json
30
+ assert_equal :json, obj_format[@layout]
31
+
29
32
  @layout = ::Logging::Layout.new 'format_as' => :yaml
30
33
  assert_equal :yaml, obj_format[@layout]
31
34
 
@@ -73,6 +76,10 @@ module TestLogging
73
76
  r = @layout.format_obj obj
74
77
  assert_equal '<Array> ["one", "two", "three", "four"]', r
75
78
 
79
+ @layout = ::Logging::Layout.new :format_as => :json
80
+ r = @layout.format_obj obj
81
+ assert_equal '<Array> ["one","two","three","four"]', r
82
+
76
83
  @layout = ::Logging::Layout.new :format_as => :yaml
77
84
  r = @layout.format_obj obj
78
85
  assert_match %r/\A<Array> \n--- ?\n- one\n- two\n- three\n- four\n/, r
@@ -1,5 +1,5 @@
1
1
 
2
- require File.expand_path('setup', File.dirname(__FILE__))
2
+ require File.expand_path('../setup', __FILE__)
3
3
 
4
4
  module TestLogging
5
5
 
@@ -231,6 +231,11 @@ module TestLogging
231
231
  assert_equal :inspect, ::Logging::OBJ_FORMAT
232
232
  remove_const[:OBJ_FORMAT]
233
233
 
234
+ ::Logging.format_as :json
235
+ assert ::Logging.const_defined?('OBJ_FORMAT')
236
+ assert_equal :json, ::Logging::OBJ_FORMAT
237
+ remove_const[:OBJ_FORMAT]
238
+
234
239
  ::Logging.format_as :yaml
235
240
  assert ::Logging.const_defined?('OBJ_FORMAT')
236
241
  assert_equal :yaml, ::Logging::OBJ_FORMAT
@@ -0,0 +1,78 @@
1
+
2
+ require File.expand_path('../setup', __FILE__)
3
+
4
+ module TestLogging
5
+
6
+ class TestMappedDiagnosticContext < Test::Unit::TestCase
7
+ include LoggingTestCase
8
+
9
+ def test_key_value_access
10
+ assert_nil Logging.mdc['foo']
11
+
12
+ Logging.mdc['foo'] = 'bar'
13
+ assert_equal 'bar', Logging.mdc[:foo]
14
+ assert_same Logging.mdc['foo'], Logging.mdc[:foo]
15
+
16
+ Logging.mdc.delete(:foo)
17
+ assert_nil Logging.mdc['foo']
18
+ end
19
+
20
+ def test_clear
21
+ Logging.mdc['foo'] = 'bar'
22
+ Logging.mdc['baz'] = 'buz'
23
+
24
+ assert_equal 'bar', Logging.mdc[:foo]
25
+ assert_equal 'buz', Logging.mdc[:baz]
26
+
27
+ Logging.mdc.clear
28
+
29
+ assert_nil Logging.mdc['foo']
30
+ assert_nil Logging.mdc['baz']
31
+ end
32
+
33
+ def test_thread_uniqueness
34
+ Logging.mdc['foo'] = 'bar'
35
+ Logging.mdc['baz'] = 'buz'
36
+
37
+ t = Thread.new {
38
+ sleep
39
+
40
+ Logging.mdc.clear
41
+ assert_nil Logging.mdc['foo']
42
+ assert_nil Logging.mdc['baz']
43
+
44
+ Logging.mdc['foo'] = 42
45
+ assert_equal 42, Logging.mdc['foo']
46
+ }
47
+
48
+ Thread.pass until t.status == 'sleep'
49
+ t.run
50
+ t.join
51
+
52
+ assert_equal 'bar', Logging.mdc['foo']
53
+ assert_equal 'buz', Logging.mdc['baz']
54
+ end
55
+
56
+ def test_thread_inheritance
57
+ Logging.mdc['foo'] = 'bar'
58
+ Logging.mdc['baz'] = 'buz'
59
+
60
+ t = Thread.new(Logging.mdc.context) { |context|
61
+ sleep
62
+
63
+ assert_not_equal context.object_id, Logging.mdc.context.object_id
64
+
65
+ assert_equal 'bar', Logging.mdc['foo']
66
+ assert_equal 'buz', Logging.mdc['baz']
67
+ assert_nil Logging.mdc['unique']
68
+ }
69
+
70
+ Thread.pass until t.status == 'sleep'
71
+ Logging.mdc['unique'] = 'value'
72
+
73
+ t.run
74
+ t.join
75
+ end
76
+
77
+ end # class TestMappedDiagnosticContext
78
+ end # module TestLogging
@@ -0,0 +1,83 @@
1
+
2
+ require File.expand_path('../setup', __FILE__)
3
+
4
+ module TestLogging
5
+
6
+ class TestNestedDiagnosticContext < Test::Unit::TestCase
7
+ include LoggingTestCase
8
+
9
+ def test_push_pop
10
+ ary = Logging.ndc.context
11
+ assert ary.empty?
12
+
13
+ assert_nil Logging.ndc.peek
14
+
15
+ Logging.ndc.push 'first context'
16
+ assert_equal 'first context', Logging.ndc.peek
17
+
18
+ Logging.ndc << 'second'
19
+ Logging.ndc << 'third'
20
+ assert_equal 'third', Logging.ndc.peek
21
+ assert_equal 3, ary.length
22
+
23
+ assert_equal 'third', Logging.ndc.pop
24
+ assert_equal 2, ary.length
25
+
26
+ assert_equal 'second', Logging.ndc.pop
27
+ assert_equal 1, ary.length
28
+
29
+ assert_equal 'first context', Logging.ndc.pop
30
+ assert ary.empty?
31
+ end
32
+
33
+ def test_clear
34
+ ary = Logging.ndc.context
35
+ assert ary.empty?
36
+
37
+ Logging.ndc << 'a' << 'b' << 'c' << 'd'
38
+ assert_equal 'd', Logging.ndc.peek
39
+ assert_equal 4, ary.length
40
+
41
+ Logging.ndc.clear
42
+ assert_nil Logging.ndc.peek
43
+ assert ary.empty?
44
+ end
45
+
46
+ def test_thread_uniqueness
47
+ Logging.ndc << 'first' << 'second'
48
+
49
+ t = Thread.new {
50
+ sleep
51
+
52
+ Logging.ndc.clear
53
+ assert_nil Logging.ndc.peek
54
+
55
+ Logging.ndc << 42
56
+ assert_equal 42, Logging.ndc.peek
57
+ }
58
+
59
+ Thread.pass until t.status == 'sleep'
60
+ t.run
61
+ t.join
62
+
63
+ assert_equal 'second', Logging.ndc.peek
64
+ end
65
+
66
+ def test_thread_inheritance
67
+ Logging.ndc << 'first' << 'second'
68
+
69
+ t = Thread.new(Logging.ndc.context) { |ary|
70
+ sleep
71
+
72
+ assert_not_equal ary.object_id, Logging.ndc.context.object_id
73
+ assert_equal %w[first second], Logging.ndc.context
74
+ }
75
+
76
+ Thread.pass until t.status == 'sleep'
77
+ Logging.ndc << 'third'
78
+
79
+ t.run
80
+ t.join
81
+ end
82
+ end # class TestNestedDiagnosticContext
83
+ end # module TestLogging
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.8.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000Z
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: little-plugger
16
- requirement: &2155744060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,40 +21,76 @@ dependencies:
21
21
  version: 1.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155744060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.3
25
30
  - !ruby/object:Gem::Dependency
26
- name: flexmock
27
- requirement: &2155743520 !ruby/object:Gem::Requirement
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.3.6
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
28
41
  none: false
29
42
  requirements:
30
43
  - - ! '>='
31
44
  - !ruby/object:Gem::Version
32
- version: 0.9.0
45
+ version: 1.3.6
46
+ - !ruby/object:Gem::Dependency
47
+ name: flexmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
33
54
  type: :development
34
55
  prerelease: false
35
- version_requirements: *2155743520
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: bones-git
38
- requirement: &2155743060 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ! '>='
42
68
  - !ruby/object:Gem::Version
43
- version: 1.2.4
69
+ version: 1.3.0
44
70
  type: :development
45
71
  prerelease: false
46
- version_requirements: *2155743060
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.0
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: bones
49
- requirement: &2155742640 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
53
84
  - !ruby/object:Gem::Version
54
- version: 3.7.2
85
+ version: 3.8.0
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *2155742640
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 3.8.0
58
94
  description: ! 'Logging is a flexible logging library for use in Ruby programs based
59
95
  on the
60
96
 
@@ -69,15 +105,12 @@ extensions: []
69
105
  extra_rdoc_files:
70
106
  - History.txt
71
107
  - README.rdoc
72
- - tmp.txt
73
108
  files:
74
109
  - .gitignore
75
- - .rvmrc
76
110
  - .travis.yml
77
111
  - History.txt
78
112
  - README.rdoc
79
113
  - Rakefile
80
- - a.rb
81
114
  - data/bad_logging_1.rb
82
115
  - data/bad_logging_2.rb
83
116
  - data/logging.rb
@@ -92,6 +125,7 @@ files:
92
125
  - examples/hierarchies.rb
93
126
  - examples/layouts.rb
94
127
  - examples/loggers.rb
128
+ - examples/mdc.rb
95
129
  - examples/names.rb
96
130
  - examples/simple.rb
97
131
  - lib/logging.rb
@@ -109,6 +143,7 @@ files:
109
143
  - lib/logging/color_scheme.rb
110
144
  - lib/logging/config/configurator.rb
111
145
  - lib/logging/config/yaml_configurator.rb
146
+ - lib/logging/diagnostic_context.rb
112
147
  - lib/logging/layout.rb
113
148
  - lib/logging/layouts.rb
114
149
  - lib/logging/layouts/basic.rb
@@ -150,12 +185,13 @@ files:
150
185
  - test/test_log_event.rb
151
186
  - test/test_logger.rb
152
187
  - test/test_logging.rb
188
+ - test/test_mapped_diagnostic_context.rb
189
+ - test/test_nested_diagnostic_context.rb
153
190
  - test/test_proxy.rb
154
191
  - test/test_repository.rb
155
192
  - test/test_root_logger.rb
156
193
  - test/test_stats.rb
157
194
  - test/test_utils.rb
158
- - tmp.txt
159
195
  - version.txt
160
196
  homepage: http://rubygems.org/gems/logging
161
197
  licenses: []
@@ -179,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
215
  version: '0'
180
216
  requirements: []
181
217
  rubyforge_project: logging
182
- rubygems_version: 1.8.11
218
+ rubygems_version: 1.8.24
183
219
  signing_key:
184
220
  specification_version: 3
185
221
  summary: A flexible and extendable logging library for Ruby
@@ -208,6 +244,8 @@ test_files:
208
244
  - test/test_log_event.rb
209
245
  - test/test_logger.rb
210
246
  - test/test_logging.rb
247
+ - test/test_mapped_diagnostic_context.rb
248
+ - test/test_nested_diagnostic_context.rb
211
249
  - test/test_proxy.rb
212
250
  - test/test_repository.rb
213
251
  - test/test_root_logger.rb