lumber 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.13.1 (09/19/2012)
2
+ -------------------
3
+
4
+ add mdc formatter helper <f54713e>
5
+
1
6
  0.13.0 (08/10/2012)
2
7
  -------------------
3
8
 
@@ -14,5 +14,7 @@ log4r_config:
14
14
  trunc: 'false'
15
15
  formatter :
16
16
  date_pattern: '%H:%M:%S'
17
- pattern : '%-5l %d #{hostname} %c[#{Process.pid}]: %m'
17
+ pattern : '%-5l %d %C(#{hostname}:#{Process.pid}) [#{Lumber.format_mdc}]: %M'
18
18
  type : PatternFormatter
19
+
20
+
data/lib/lumber/lumber.rb CHANGED
@@ -119,6 +119,13 @@ module Lumber
119
119
  end
120
120
  end
121
121
 
122
+ # Helper to make it easier to log context through log4r.yml
123
+ def format_mdc()
124
+ ctx = Log4r::MDC.get_context.collect {|k, v| k.to_s + "=" + v.to_s }.join(" ")
125
+ ctx.gsub!('%', '%%')
126
+ return ctx
127
+ end
128
+
122
129
  private
123
130
 
124
131
  # Adds a inheritance handler to Object so we can know to add loggers
@@ -1,3 +1,3 @@
1
1
  module Lumber
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
data/spec/lumber_spec.rb CHANGED
@@ -154,4 +154,27 @@ describe Lumber do
154
154
  assert_valid_logger('Foo3', "root::Foo1::Foo3")
155
155
  end
156
156
 
157
+ context "formatted MDC context" do
158
+
159
+ before(:each) do
160
+ Log4r::MDC.get_context.keys.each {|k| Log4r::MDC.remove(k) }
161
+ end
162
+
163
+ it "is empty for no context" do
164
+ Lumber.format_mdc.should == ""
165
+ end
166
+
167
+ it "has context vars" do
168
+ Log4r::MDC.put("foo", "bar")
169
+ Log4r::MDC.put("baz", "boo")
170
+ Lumber.format_mdc.should == "foo=bar baz=boo"
171
+ end
172
+
173
+ it "escapes %" do
174
+ Log4r::MDC.put("%foo", "%bar")
175
+ Lumber.format_mdc.should == "%%foo=%%bar"
176
+ end
177
+
178
+ end
179
+
157
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r
@@ -235,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: 2273159776171190626
238
+ hash: 820786214147561006
239
239
  required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  none: false
241
241
  requirements:
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
244
  version: '0'
245
245
  segments:
246
246
  - 0
247
- hash: 2273159776171190626
247
+ hash: 820786214147561006
248
248
  requirements: []
249
249
  rubyforge_project:
250
250
  rubygems_version: 1.8.24