lumber 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a46d745783b60fff11ef0721004f12f9f63bd96
4
- data.tar.gz: 3eba30bf67000eb632ed7a43b874b9311c06ea7d
3
+ metadata.gz: e6695093aa77737d03320b495d979a1cbb8bd88f
4
+ data.tar.gz: 22f4e7ea92bb1582ddbfae50c2e308250e59eb20
5
5
  SHA512:
6
- metadata.gz: 90f2ac82d2c07a1c41de9f1135bf635826829bb26f055d65c0d71935276eb407a5f07f23e27a2bdcb41075f655492ce566392f8606cac0c440df7fac4f8874bc
7
- data.tar.gz: e982a2aa70f9201f721cbd05fb9a32a7a6cdf651e9a2afb3ad324a9e3ae1bf4035c734049a4c4b52be67ef4b9c0480c61b5cb8cd2f96bc1c7955a1664376eef4
6
+ metadata.gz: 45c8f777f62c0bf92c1eb8758815e0bf99b5e1d50d71e0fda8f431a36fc5e846085e56c90acc2832a43fceddc2ca409dc3d7fe0d2b9926e2e56b6e40e2b0e139
7
+ data.tar.gz: 91fe68609b03ae3a48f2cfe4b9269361fef12bb7f20a64d5cf9aee37092de66458c14b69d89e17811d0324dc481d916fbdb07662fd683a572f9eedba5c644b2b
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 1.0.2 (10/11/2013)
2
+ ------------------
3
+
4
+ add ability to add constant fields to json output <b99703a> [Matt Conway]
5
+
1
6
  1.0.1 (10/11/2013)
2
7
  ------------------
3
8
 
@@ -6,13 +6,23 @@ module Lumber
6
6
  class JsonFormatter < Log4r::BasicFormatter
7
7
 
8
8
  def initialize(hash={})
9
- @key_mapping = {}
10
9
  mapping = hash['key_mapping'] || {}
11
10
  @key_mapping = Hash[mapping.collect {|k, v| [k.to_s, v.to_s.split('.')]}]
11
+
12
+ @fields = {}
13
+ fields = hash['fields'] || {}
14
+ fields.each do |k, v|
15
+ if v.kind_of? String
16
+ @fields[k.to_s] = v.to_s.gsub(/#\{(.+)\}/) {|m| eval($1) }
17
+ else
18
+ @fields[k.to_s] = v
19
+ end
20
+ end
12
21
  end
13
22
 
14
23
  def format(logevent)
15
- data = {}
24
+ data = @fields.dup
25
+
16
26
  assign_mapped_key(data, :timestamp, Time.now.to_s)
17
27
  assign_mapped_key(data, :logger, logevent.fullname)
18
28
  assign_mapped_key(data, :level, Log4r::LNAMES[logevent.level].downcase)
@@ -1,3 +1,3 @@
1
1
  module Lumber
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -27,7 +27,7 @@ describe Lumber::JsonFormatter do
27
27
  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
28
28
  end
29
29
 
30
- it "can receive configuration" do
30
+ it "can receive key_mapping configuration" do
31
31
  yml = <<-EOF
32
32
  log4r_config:
33
33
  pre_config:
@@ -54,6 +54,34 @@ describe Lumber::JsonFormatter do
54
54
  outputter.formatter.instance_variable_get(:@key_mapping).should eq({'level' => ['severity'], 'backtrace' => ['exception', 'bt']})
55
55
  end
56
56
 
57
+ it "can receive fields configuration" do
58
+ yml = <<-'EOF'
59
+ log4r_config:
60
+ pre_config:
61
+ root:
62
+ level: 'DEBUG'
63
+ loggers:
64
+ - name: "mylogger"
65
+
66
+ outputters:
67
+ - type: StdoutOutputter
68
+ name: stdout
69
+ formatter:
70
+ type: JsonFormatter
71
+ fields:
72
+ version: 1
73
+ dynamic: "#{1+1}"
74
+ EOF
75
+ yml.should include('#{1+1}')
76
+ cfg = Log4r::YamlConfigurator
77
+ cfg['hostname'] = 'foo'
78
+ cfg.load_yaml_string(yml)
79
+ outputter = Log4r::Outputter['stdout']
80
+ outputter.formatter.should_not be_nil
81
+ outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
82
+ outputter.formatter.instance_variable_get(:@fields).should eq({'version' => 1, 'dynamic' => '2'})
83
+ end
84
+
57
85
  end
58
86
 
59
87
  context "#assign_mapped_key" do
@@ -129,6 +157,16 @@ describe Lumber::JsonFormatter do
129
157
  json['severity'].should == 'info'
130
158
  end
131
159
 
160
+ it "logs as json with fields" do
161
+ @formatter = Lumber::JsonFormatter.new('fields' => {'version' => 1})
162
+ @outputter.formatter = @formatter
163
+
164
+ @logger.info("howdy")
165
+ json = JSON.parse(@sio.string)
166
+ json['message'].should == 'howdy'
167
+ json['version'].should == 1
168
+ end
169
+
132
170
  it "logs exception as json" do
133
171
  ex = StandardError.new("mybad")
134
172
  raise ex rescue nil
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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway