steno 1.2.4 → 1.3.5

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 (43) hide show
  1. checksums.yaml +5 -13
  2. data/NOTICE +14 -0
  3. data/Rakefile +6 -8
  4. data/bin/steno-prettify +24 -25
  5. data/lib/steno/codec/base.rb +1 -1
  6. data/lib/steno/codec/json.rb +24 -14
  7. data/lib/steno/codec.rb +2 -2
  8. data/lib/steno/config.rb +23 -30
  9. data/lib/steno/context.rb +3 -3
  10. data/lib/steno/json_prettifier.rb +31 -30
  11. data/lib/steno/log_level.rb +1 -2
  12. data/lib/steno/logger.rb +22 -26
  13. data/lib/steno/record.rb +5 -15
  14. data/lib/steno/sink/base.rb +2 -3
  15. data/lib/steno/sink/counter.rb +4 -8
  16. data/lib/steno/sink/eventlog.rb +16 -17
  17. data/lib/steno/sink/fluentd.rb +4 -5
  18. data/lib/steno/sink/io.rb +8 -12
  19. data/lib/steno/sink/syslog.rb +19 -15
  20. data/lib/steno/sink.rb +6 -6
  21. data/lib/steno/tagged_logger.rb +2 -3
  22. data/lib/steno/version.rb +1 -1
  23. data/lib/steno.rb +16 -21
  24. data/spec/spec_helper.rb +4 -4
  25. data/spec/support/barrier.rb +2 -2
  26. data/spec/support/shared_context_specs.rb +4 -4
  27. data/spec/unit/config_spec.rb +134 -133
  28. data/spec/unit/context_spec.rb +19 -19
  29. data/spec/unit/core_ext_spec.rb +14 -14
  30. data/spec/unit/json_codec_spec.rb +43 -23
  31. data/spec/unit/json_prettifier_spec.rb +25 -25
  32. data/spec/unit/log_level_spec.rb +8 -9
  33. data/spec/unit/logger_spec.rb +53 -53
  34. data/spec/unit/record_spec.rb +15 -15
  35. data/spec/unit/sink/counter_spec.rb +7 -7
  36. data/spec/unit/sink/eventlog_spec.rb +14 -15
  37. data/spec/unit/sink/fluentd_spec.rb +28 -28
  38. data/spec/unit/sink/io_spec.rb +62 -62
  39. data/spec/unit/sink/syslog_spec.rb +54 -30
  40. data/spec/unit/steno_spec.rb +33 -33
  41. data/spec/unit/tagged_logger_spec.rb +20 -18
  42. data/steno.gemspec +28 -28
  43. metadata +62 -53
@@ -1,221 +1,222 @@
1
- require "fileutils"
2
- require "yaml"
1
+ require 'fileutils'
2
+ require 'yaml'
3
3
 
4
- require "spec_helper"
4
+ require 'spec_helper'
5
5
 
6
6
  describe Steno::Config do
7
-
8
7
  if Steno::Sink::WINDOWS
9
- describe ".from_hash" do
10
- before :each do
11
- @log_path = "some_file"
12
-
13
- @mock_sink_file = double("sink")
14
- @mock_sink_file.stub(:codec=)
15
- Steno::Sink::IO.should_receive(:for_file).with(@log_path,
16
- :max_retries => 5)
17
- .and_return(@mock_sink_file)
18
-
19
- @mock_sink_eventlog = double("sink")
20
- @mock_sink_eventlog.stub(:codec=)
21
- @mock_sink_eventlog.should_receive(:open).with("test")
22
- Steno::Sink::Eventlog.should_receive(:instance).twice()
23
- .and_return(@mock_sink_eventlog)
8
+ describe '.from_hash' do
9
+ before do
10
+ @log_path = 'some_file'
11
+
12
+ @mock_sink_file = double('sink')
13
+ expect(@mock_sink_file).to receive(:codec=)
14
+ expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
15
+ max_retries: 5)
16
+ .and_return(@mock_sink_file)
17
+
18
+ @mock_sink_eventlog = double('sink')
19
+ expect(@mock_sink_eventlog).to receive(:codec=)
20
+ expect(@mock_sink_eventlog).to receive(:open).with('test')
21
+ expect(Steno::Sink::Eventlog).to receive(:instance).twice
22
+ .and_return(@mock_sink_eventlog)
24
23
  end
25
24
 
26
- after :each do
25
+ after do
27
26
  @config = Steno::Config.from_hash(@hash)
28
27
 
29
- @config.default_log_level.should == :debug2
30
- @config.context.should.class == Steno::Context::Null
31
- @config.codec.should.class == Steno::Codec::Json
28
+ expect(@config.default_log_level).to eq(:debug2)
29
+ expect(@config.context.class).to eq(Steno::Context::Null)
30
+ expect(@config.codec.class).to eq(Steno::Codec::Json)
32
31
 
33
- @config.sinks.size.should == 2
34
- @config.sinks.should =~ [@mock_sink_file, @mock_sink_eventlog]
32
+ expect(@config.sinks.size).to eq(2)
33
+ expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_eventlog)
35
34
  end
36
35
 
37
- it "should work for symbolized keys" do
36
+ it 'works for symbolized keys' do
38
37
  @hash = {
39
- :file => @log_path,
40
- :level => "debug2",
41
- :default_log_level => "warn",
42
- :eventlog => "test",
43
- :max_retries => 5,
38
+ file: @log_path,
39
+ level: 'debug2',
40
+ default_log_level: 'warn',
41
+ eventlog: 'test',
42
+ max_retries: 5
44
43
  }
45
44
  end
46
45
 
47
- it "should work for non-symbolized keys" do
46
+ it 'works for non-symbolized keys' do
48
47
  @hash = {
49
- "file" => @log_path,
50
- "level" => "debug2",
51
- "default_log_level" => "warn",
52
- "eventlog" => "test",
53
- "max_retries" => 5,
48
+ 'file' => @log_path,
49
+ 'level' => 'debug2',
50
+ 'default_log_level' => 'warn',
51
+ 'eventlog' => 'test',
52
+ 'max_retries' => 5
54
53
  }
55
54
  end
56
-
57
55
  end
58
56
  else
59
- describe ".from_hash" do
60
- before :each do
61
- @log_path = "some_file"
62
-
63
- @mock_sink_file = double("sink")
64
- @mock_sink_file.stub(:codec=)
65
- Steno::Sink::IO.should_receive(:for_file).with(@log_path,
66
- :max_retries => 5)
67
- .and_return(@mock_sink_file)
68
-
69
- @mock_sink_syslog = double("sink")
70
- @mock_sink_syslog.stub(:codec=)
71
- @mock_sink_syslog.should_receive(:open).with("test")
72
- Steno::Sink::Syslog.should_receive(:instance).twice()
73
- .and_return(@mock_sink_syslog)
57
+ describe '.from_hash' do
58
+ before do
59
+ @log_path = 'some_file'
60
+
61
+ @mock_sink_file = double('sink')
62
+ allow(@mock_sink_file).to receive(:codec=)
63
+ expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
64
+ max_retries: 5)
65
+ .and_return(@mock_sink_file)
66
+
67
+ @mock_sink_syslog = double('sink')
68
+ expect(@mock_sink_syslog).to receive(:codec=)
69
+ expect(@mock_sink_syslog).to receive(:open).with('test')
70
+ expect(Steno::Sink::Syslog).to receive(:instance).twice
71
+ .and_return(@mock_sink_syslog)
74
72
  end
75
73
 
76
- after :each do
74
+ after do
77
75
  @config = Steno::Config.from_hash(@hash)
78
76
 
79
- @config.default_log_level.should == :debug2
80
- @config.context.should.class == Steno::Context::Null
81
- @config.codec.should.class == Steno::Codec::Json
77
+ expect(@config.default_log_level).to eq(:debug2)
78
+ expect(@config.context.class).to eq(Steno::Context::Null)
79
+ expect(@config.codec.class).to eq(Steno::Codec::Json)
82
80
 
83
- @config.sinks.size.should == 2
84
- @config.sinks.should =~ [@mock_sink_file, @mock_sink_syslog]
81
+ expect(@config.sinks.size).to eq(2)
82
+ expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_syslog)
85
83
  end
86
84
 
87
- it "should work for symbolized keys" do
85
+ it 'works for symbolized keys' do
88
86
  @hash = {
89
- :file => @log_path,
90
- :level => "debug2",
91
- :default_log_level => "warn",
92
- :syslog => "test",
93
- :max_retries => 5,
87
+ file: @log_path,
88
+ level: 'debug2',
89
+ default_log_level: 'warn',
90
+ syslog: 'test',
91
+ max_retries: 5
94
92
  }
95
93
  end
96
94
 
97
- it "should work for non-symbolized keys" do
95
+ it 'works for non-symbolized keys' do
98
96
  @hash = {
99
- "file" => @log_path,
100
- "level" => "debug2",
101
- "default_log_level" => "warn",
102
- "syslog" => "test",
103
- "max_retries" => 5,
97
+ 'file' => @log_path,
98
+ 'level' => 'debug2',
99
+ 'default_log_level' => 'warn',
100
+ 'syslog' => 'test',
101
+ 'max_retries' => 5
104
102
  }
105
103
  end
106
-
107
104
  end
108
105
  end
109
106
 
110
- describe ".from_file" do
111
- before :each do
107
+ describe '.from_file' do
108
+ before do
112
109
  @tmpdir = Dir.mktmpdir
113
- @config_path = File.join(@tmpdir, "config.yml")
114
- @log_path = File.join(@tmpdir, "test.log")
110
+ @config_path = File.join(@tmpdir, 'config.yml')
111
+ @log_path = File.join(@tmpdir, 'test.log')
115
112
  end
116
113
 
117
- after :each do
114
+ after do
118
115
  FileUtils.rm_rf(@tmpdir)
119
116
  end
120
117
 
121
- it "should return Steno::Config instance with sane defaults" do
118
+ it 'returns Steno::Config instance with sane defaults' do
122
119
  write_config(@config_path, {})
123
120
 
124
121
  config = Steno::Config.from_file(@config_path)
125
122
 
126
- config.sinks.size.should == 1
127
- config.sinks[0].class.should == Steno::Sink::IO
123
+ expect(config.sinks.size).to eq(1)
124
+ expect(config.sinks[0].class).to eq(Steno::Sink::IO)
128
125
 
129
- config.default_log_level.should == :info
126
+ expect(config.default_log_level).to eq(:info)
130
127
 
131
- config.context.should.class == Steno::Context::Null
128
+ expect(config.context.class).to eq(Steno::Context::Null)
132
129
 
133
- config.codec.should.class == Steno::Codec::Json
130
+ expect(config.codec.class).to eq(Steno::Codec::Json)
131
+ expect(config.codec.iso8601_timestamps?).to eq(false)
134
132
  end
135
133
 
136
- it "should set the default_log_level if a key with the same name is supplied" do
137
- write_config(@config_path, {"level" => "debug2"})
138
- Steno::Config.from_file(@config_path).default_log_level.should == :debug2
134
+ it 'configures json codec with readable dates if iso8601_timestamps is true' do
135
+ write_config(@config_path, { 'iso8601_timestamps' => 'true' })
136
+ config = Steno::Config.from_file(@config_path)
137
+ expect(config.codec.class).to eq(Steno::Codec::Json)
138
+ expect(config.codec.iso8601_timestamps?).to eq(true)
139
+ end
139
140
 
140
- write_config(@config_path, {"default_log_level" => "debug2"})
141
- Steno::Config.from_file(@config_path).default_log_level.should == :debug2
141
+ it 'sets the default_log_level if a key with the same name is supplied' do
142
+ write_config(@config_path, { 'level' => 'debug2' })
143
+ expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
144
+
145
+ write_config(@config_path, { 'default_log_level' => 'debug2' })
146
+ expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
142
147
  end
143
148
 
144
- it "should read the 'level' key if both default_log_level and level are spscified" do
145
- write_config(@config_path, {"level" => "debug2",
146
- "default_log_level" => "warn"})
147
- Steno::Config.from_file(@config_path).default_log_level.should == :debug2
149
+ it "reads the 'level' key if both default_log_level and level are spscified" do
150
+ write_config(@config_path, { 'level' => 'debug2',
151
+ 'default_log_level' => 'warn' })
152
+ expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
148
153
  end
149
154
 
150
- it "should add a file sink if the 'file' key is specified" do
151
- write_config(@config_path, {"file" => @log_path, "max_retries" => 2})
152
- mock_sink = double("sink")
153
- mock_sink.stub(:codec=)
155
+ it "adds a file sink if the 'file' key is specified" do
156
+ write_config(@config_path, { 'file' => @log_path, 'max_retries' => 2 })
157
+ mock_sink = double('sink')
158
+ expect(mock_sink).to receive(:codec=)
154
159
 
155
- Steno::Sink::IO.should_receive(:for_file).
156
- with(@log_path, :max_retries => 2).and_return(mock_sink)
160
+ expect(Steno::Sink::IO).to receive(:for_file)
161
+ .with(@log_path, max_retries: 2).and_return(mock_sink)
157
162
  config = Steno::Config.from_file(@config_path)
158
- config.sinks.size.should == 1
159
- config.sinks[0].should == mock_sink
163
+ expect(config.sinks.size).to eq(1)
164
+ expect(config.sinks[0]).to eq(mock_sink)
160
165
  end
161
166
 
162
167
  if Steno::Sink::WINDOWS
163
- it "should add a event sink if the 'eventlog' key is specified" do
164
- write_config(@config_path, {"eventlog" => "test"})
165
- mock_sink = double("sink")
166
- mock_sink.should_receive(:open).with("test")
167
- mock_sink.stub(:codec=)
168
+ it "adds a event sink if the 'eventlog' key is specified" do
169
+ write_config(@config_path, { 'eventlog' => 'test' })
170
+ mock_sink = double('sink')
171
+ expect(mock_sink).to receive(:open).with('test')
172
+ expect(mock_sink).to receive(:codec=)
168
173
 
169
- Steno::Sink::Eventlog.should_receive(:instance).twice().and_return(mock_sink)
174
+ expect(Steno::Sink::Eventlog).to receive(:instance).twice.and_return(mock_sink)
170
175
 
171
176
  config = Steno::Config.from_file(@config_path)
172
- config.sinks.size.should == 1
173
- config.sinks[0].should == mock_sink
177
+ expect(config.sinks.size).to eq(1)
178
+ expect(config.sinks[0]).to eq(mock_sink)
174
179
  end
175
180
  else
176
- it "should add a syslog sink if the 'syslog' key is specified" do
177
- write_config(@config_path, {"syslog" => "test"})
178
- mock_sink = double("sink")
179
- mock_sink.should_receive(:open).with("test")
180
- mock_sink.stub(:codec=)
181
+ it "adds a syslog sink if the 'syslog' key is specified" do
182
+ write_config(@config_path, { 'syslog' => 'test' })
183
+ mock_sink = double('sink')
184
+ expect(mock_sink).to receive(:open).with('test')
185
+ expect(mock_sink).to receive(:codec=)
181
186
 
182
- Steno::Sink::Syslog.should_receive(:instance).twice().and_return(mock_sink)
187
+ expect(Steno::Sink::Syslog).to receive(:instance).twice.and_return(mock_sink)
183
188
 
184
189
  config = Steno::Config.from_file(@config_path)
185
- config.sinks.size.should == 1
186
- config.sinks[0].should == mock_sink
190
+ expect(config.sinks.size).to eq(1)
191
+ expect(config.sinks[0]).to eq(mock_sink)
187
192
  end
188
193
  end
189
194
 
190
-
191
-
192
- it "should add an io sink to stdout if no sinks are explicitly specified in the config file" do
195
+ it 'adds an io sink to stdout if no sinks are explicitly specified in the config file' do
193
196
  write_config(@config_path, {})
194
- mock_sink = double("sink")
195
- mock_sink.stub(:codec=)
197
+ mock_sink = double('sink')
198
+ expect(mock_sink).to receive(:codec=)
196
199
 
197
- Steno::Sink::IO.should_receive(:new).with(STDOUT).and_return(mock_sink)
200
+ expect(Steno::Sink::IO).to receive(:new).with(STDOUT).and_return(mock_sink)
198
201
 
199
202
  config = Steno::Config.from_file(@config_path)
200
- config.sinks.size.should == 1
201
- config.sinks[0].should == mock_sink
203
+ expect(config.sinks.size).to eq(1)
204
+ expect(config.sinks[0]).to eq(mock_sink)
202
205
  end
203
206
 
204
- it "should merge supplied overrides with the file based config" do
205
- write_config(@config_path, {"default_log_level" => "debug"})
207
+ it 'merges supplied overrides with the file based config' do
208
+ write_config(@config_path, { 'default_log_level' => 'debug' })
206
209
 
207
210
  context = Steno::Context::ThreadLocal.new
208
211
  config = Steno::Config.from_file(@config_path,
209
- :default_log_level => "warn",
210
- :context => context)
211
- config.context.should == context
212
- config.default_log_level.should == :warn
212
+ default_log_level: 'warn',
213
+ context: context)
214
+ expect(config.context).to eq(context)
215
+ expect(config.default_log_level).to eq(:warn)
213
216
  end
214
217
  end
215
218
 
216
219
  def write_config(path, config)
217
- File.open(path, "w+") do |f|
218
- f.write(YAML.dump({"logging" => config}))
219
- end
220
+ File.write(path, YAML.dump({ 'logging' => config }))
220
221
  end
221
222
  end
@@ -1,37 +1,37 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Context::Null do
4
- include_context :steno_context
4
+ include_context 'steno context'
5
5
 
6
6
  let(:context) { Steno::Context::Null.new }
7
7
 
8
- it "should store no data" do
9
- context.data.should == {}
10
- context.data["foo"] = "bar"
11
- context.data.should == {}
8
+ it 'stores no data' do
9
+ expect(context.data).to eq({})
10
+ context.data['foo'] = 'bar'
11
+ expect(context.data).to eq({})
12
12
  end
13
13
  end
14
14
 
15
15
  describe Steno::Context::ThreadLocal do
16
- include_context :steno_context
16
+ include_context 'steno context'
17
17
 
18
- let (:context) { Steno::Context::ThreadLocal.new }
18
+ let(:context) { Steno::Context::ThreadLocal.new }
19
19
 
20
- it "should store data local to threads" do
20
+ it 'stores data local to threads' do
21
21
  b1 = Barrier.new
22
22
  b2 = Barrier.new
23
23
 
24
24
  t1 = Thread.new do
25
- context.data["thread"] = "t1"
25
+ context.data['thread'] = 't1'
26
26
  b1.release
27
27
  b2.wait
28
- context.data["thread"].should == "t1"
28
+ expect(context.data['thread']).to eq('t1')
29
29
  end
30
30
 
31
31
  t2 = Thread.new do
32
32
  b1.wait
33
- context.data["thread"].should be_nil
34
- context.data["thread"] = "t2"
33
+ expect(context.data['thread']).to be_nil
34
+ context.data['thread'] = 't2'
35
35
  b2.release
36
36
  end
37
37
 
@@ -41,20 +41,20 @@ describe Steno::Context::ThreadLocal do
41
41
  end
42
42
 
43
43
  describe Steno::Context::FiberLocal do
44
- include_context :steno_context
44
+ include_context 'steno context'
45
45
 
46
46
  let(:context) { Steno::Context::FiberLocal.new }
47
47
 
48
- it "should store data local to fibers" do
48
+ it 'stores data local to fibers' do
49
49
  f2 = Fiber.new do
50
- context.data["fiber"].should be_nil
51
- context.data["fiber"] = "f2"
50
+ expect(context.data['fiber']).to be_nil
51
+ context.data['fiber'] = 'f2'
52
52
  end
53
53
 
54
54
  f1 = Fiber.new do
55
- context.data["fiber"] = "f1"
55
+ context.data['fiber'] = 'f1'
56
56
  f2.resume
57
- context.data["fiber"].should == "f1"
57
+ expect(context.data['fiber']).to eq('f1')
58
58
  end
59
59
 
60
60
  f1.resume
@@ -1,6 +1,6 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "steno/core_ext"
3
+ require 'steno/core_ext'
4
4
 
5
5
  module Foo
6
6
  class Bar
@@ -8,31 +8,31 @@ module Foo
8
8
  end
9
9
 
10
10
  describe Module do
11
- describe "#logger" do
12
- it "should request a logger named after itself" do
11
+ describe '#logger' do
12
+ it 'requests a logger named after itself' do
13
13
  x = Foo.logger
14
- x.should be_a(Steno::Logger)
15
- x.name.should include("Foo")
14
+ expect(x).to be_a(Steno::Logger)
15
+ expect(x.name).to include('Foo')
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
20
  describe Class do
21
- describe "#logger" do
22
- it "should request a logger named after itself" do
21
+ describe '#logger' do
22
+ it 'requests a logger named after itself' do
23
23
  x = Foo::Bar.logger
24
- x.should be_a(Steno::Logger)
25
- x.name.should include("Foo::Bar")
24
+ expect(x).to be_a(Steno::Logger)
25
+ expect(x.name).to include('Foo::Bar')
26
26
  end
27
27
  end
28
28
  end
29
29
 
30
30
  describe Object do
31
- describe "#logger" do
32
- it "should request a logger named after its class" do
31
+ describe '#logger' do
32
+ it 'requests a logger named after its class' do
33
33
  x = Foo::Bar.new.logger
34
- x.should be_a(Steno::Logger)
35
- x.name.should include("Foo::Bar")
34
+ expect(x).to be_a(Steno::Logger)
35
+ expect(x.name).to include('Foo::Bar')
36
36
  end
37
37
  end
38
38
  end
@@ -1,48 +1,68 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Codec::Json do
4
4
  let(:codec) { Steno::Codec::Json.new }
5
- let(:record) { make_record(:data => { "user" => "data" }) }
5
+ let(:record) { make_record(data: { 'user' => 'data' }) }
6
6
 
7
- describe "#encode_record" do
8
- it "should encode records as json hashes" do
7
+ describe '#encode_record' do
8
+ it 'encodes records as json hashes' do
9
9
  parsed = Yajl::Parser.parse(codec.encode_record(record))
10
- parsed.class.should == Hash
10
+ expect(parsed.class).to eq(Hash)
11
11
  end
12
12
 
13
- it "should encode the timestamp as a float" do
13
+ it 'encodes the timestamp as a float' do
14
14
  parsed = Yajl::Parser.parse(codec.encode_record(record))
15
- parsed["timestamp"].class.should == Float
15
+ expect(parsed['timestamp'].class).to eq(Float)
16
16
  end
17
17
 
18
- it "should escape newlines" do
19
- rec = make_record(:message => "newline\ntest")
20
- codec.encode_record(rec).should match(/newline\\ntest/)
18
+ it 'escapes newlines' do
19
+ rec = make_record(message: "newline\ntest")
20
+ expect(codec.encode_record(rec)).to match(/newline\\ntest/)
21
21
  end
22
22
 
23
- it "should escape carriage returns" do
24
- rec = make_record(:message => "newline\rtest")
25
- codec.encode_record(rec).should match(/newline\\rtest/)
23
+ it 'escapes carriage returns' do
24
+ rec = make_record(message: "newline\rtest")
25
+ expect(codec.encode_record(rec)).to match(/newline\\rtest/)
26
26
  end
27
27
 
28
- it "should allow messages with valid encodings to pass through untouched" do
28
+ it 'allows messages with valid encodings to pass through untouched' do
29
29
  msg = "HI\u2600"
30
- rec = make_record(:message => msg)
31
- codec.encode_record(rec).should match(/#{msg}/)
30
+ rec = make_record(message: msg)
31
+ expect(codec.encode_record(rec)).to match(/#{msg}/)
32
32
  end
33
33
 
34
- it "should treat messages with invalid encodings as binary data" do
35
- msg = "HI\u2026".force_encoding("US-ASCII")
36
- rec = make_record(:message => msg)
37
- codec.encode_record(rec).should match(/HI\\\\xe2\\\\x80\\\\xa6/)
34
+ it 'treats messages with invalid encodings as binary data' do
35
+ msg = "HI\u2026".force_encoding('US-ASCII')
36
+ rec = make_record(message: msg)
37
+ expect(codec.encode_record(rec)).to match(/HI\\\\xe2\\\\x80\\\\xa6/)
38
+ end
39
+
40
+ it 'does not use readable dates by default' do
41
+ expect(codec.iso8601_timestamps?).to eq(false)
42
+ end
43
+
44
+ context 'when iso8601_timestamps is set' do
45
+ let(:codec) { Steno::Codec::Json.new(iso8601_timestamps: true) }
46
+
47
+ it 'encodes timestamps as UTC-formatted strings' do
48
+ allow(record).to receive(:timestamp).and_return 1_396_473_763.811278 # 2014-04-02 22:22:43 +01:00
49
+ parsed = Yajl::Parser.parse(codec.encode_record(record))
50
+
51
+ expect(parsed['timestamp'].class).to eq(String)
52
+ expect(parsed['timestamp']).to eq('2014-04-02T21:22:43.811278Z')
53
+ end
54
+
55
+ it 'surfaces the property in a getter' do
56
+ expect(codec.iso8601_timestamps?).to eq(true)
57
+ end
38
58
  end
39
59
  end
40
60
 
41
61
  def make_record(opts = {})
42
- Steno::Record.new(opts[:source] || "my_source",
62
+ Steno::Record.new(opts[:source] || 'my_source',
43
63
  opts[:level] || :debug,
44
- opts[:message] || "test message",
64
+ opts[:message] || 'test message',
45
65
  nil,
46
- opts[:data] || {})
66
+ opts[:data] || {})
47
67
  end
48
68
  end