lumber 1.0.2 → 1.0.3

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: e6695093aa77737d03320b495d979a1cbb8bd88f
4
- data.tar.gz: 22f4e7ea92bb1582ddbfae50c2e308250e59eb20
3
+ metadata.gz: 46565c6578428e0fd2b235b3c342958c1bdd2ca2
4
+ data.tar.gz: f6d4b6262295e7e8f7eb9ffac68ae180ae9329c0
5
5
  SHA512:
6
- metadata.gz: 45c8f777f62c0bf92c1eb8758815e0bf99b5e1d50d71e0fda8f431a36fc5e846085e56c90acc2832a43fceddc2ca409dc3d7fe0d2b9926e2e56b6e40e2b0e139
7
- data.tar.gz: 91fe68609b03ae3a48f2cfe4b9269361fef12bb7f20a64d5cf9aee37092de66458c14b69d89e17811d0324dc481d916fbdb07662fd683a572f9eedba5c644b2b
6
+ metadata.gz: 252efef13b42f54c839d9b9b20908df2e6902a9b657c9452283e9dde81600ce63ebb95f9d9f2878b65eead7e2d6da8279761e00bdfb9a63a7ffba5117dec48f8
7
+ data.tar.gz: 3110b279693bea1ad2a1b522aff0c9c9ab6c57090e1a1c6b3f44adda84748af326f44a84f994144d9e296c5d05888bd621d8feed5062f5cc8108e11b4d848629
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 1.0.3 (10/11/2013)
2
+ ------------------
3
+
4
+ add date_pattern and newline at end of formatted message <90daa25> [Matt Conway]
5
+
1
6
  1.0.2 (10/11/2013)
2
7
  ------------------
3
8
 
@@ -18,12 +18,14 @@ module Lumber
18
18
  @fields[k.to_s] = v
19
19
  end
20
20
  end
21
+
22
+ @date_pattern = hash['date_pattern'] || '%H:%M:%S'
21
23
  end
22
24
 
23
25
  def format(logevent)
24
26
  data = @fields.dup
25
27
 
26
- assign_mapped_key(data, :timestamp, Time.now.to_s)
28
+ assign_mapped_key(data, :timestamp, Time.now.strftime(@date_pattern))
27
29
  assign_mapped_key(data, :logger, logevent.fullname)
28
30
  assign_mapped_key(data, :level, Log4r::LNAMES[logevent.level].downcase)
29
31
 
@@ -82,7 +84,7 @@ module Lumber
82
84
  assign_mapped_key(data, :mdc, value)
83
85
  end
84
86
 
85
- data.to_json
87
+ "#{data.to_json}\n"
86
88
  end
87
89
 
88
90
  private
@@ -1,3 +1,3 @@
1
1
  module Lumber
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -74,7 +74,6 @@ describe Lumber::JsonFormatter do
74
74
  EOF
75
75
  yml.should include('#{1+1}')
76
76
  cfg = Log4r::YamlConfigurator
77
- cfg['hostname'] = 'foo'
78
77
  cfg.load_yaml_string(yml)
79
78
  outputter = Log4r::Outputter['stdout']
80
79
  outputter.formatter.should_not be_nil
@@ -82,6 +81,30 @@ describe Lumber::JsonFormatter do
82
81
  outputter.formatter.instance_variable_get(:@fields).should eq({'version' => 1, 'dynamic' => '2'})
83
82
  end
84
83
 
84
+ it "can receive date_pattern configuration" do
85
+ yml = <<-'EOF'
86
+ log4r_config:
87
+ pre_config:
88
+ root:
89
+ level: 'DEBUG'
90
+ loggers:
91
+ - name: "mylogger"
92
+
93
+ outputters:
94
+ - type: StdoutOutputter
95
+ name: stdout
96
+ formatter:
97
+ type: JsonFormatter
98
+ date_pattern: "%M"
99
+ EOF
100
+ cfg = Log4r::YamlConfigurator
101
+ cfg.load_yaml_string(yml)
102
+ outputter = Log4r::Outputter['stdout']
103
+ outputter.formatter.should_not be_nil
104
+ outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
105
+ outputter.formatter.instance_variable_get(:@date_pattern).should == "%M"
106
+ end
107
+
85
108
  end
86
109
 
87
110
  context "#assign_mapped_key" do
@@ -167,6 +190,17 @@ describe Lumber::JsonFormatter do
167
190
  json['version'].should == 1
168
191
  end
169
192
 
193
+ it "logs as json with date format" do
194
+ now = Time.now
195
+ Time.stub(:now).and_return(now)
196
+ @formatter = Lumber::JsonFormatter.new('date_pattern' => "%s")
197
+ @outputter.formatter = @formatter
198
+
199
+ @logger.info("howdy")
200
+ json = JSON.parse(@sio.string)
201
+ json['timestamp'].should == now.to_i.to_s
202
+ end
203
+
170
204
  it "logs exception as json" do
171
205
  ex = StandardError.new("mybad")
172
206
  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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway