steno 0.0.17 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,13 +9,18 @@ Signal.trap("INT") { exit }
9
9
 
10
10
  def prettify_io(io, prettifier, ignore_parse_error = false)
11
11
  lineno = 0
12
+ json_regex = '([^{]*)({.*})'
12
13
 
13
14
  io.sync = true
14
15
 
15
16
  io.each_line do |line|
16
17
  begin
17
- prettified = prettifier.prettify_line(line)
18
- print prettified
18
+ match_data = line.match(json_regex)
19
+ prefix = match_data[1]
20
+ json = match_data[2]
21
+
22
+ prettified = prettifier.prettify_line(json)
23
+ print prefix + prettified
19
24
  rescue Steno::JsonPrettifier::ParseError => e
20
25
  if ignore_parse_error
21
26
  print line
@@ -9,6 +9,7 @@ end
9
9
  class Steno::JsonPrettifier
10
10
  FIELD_ORDER = %w[timestamp source process_id thread_id fiber_id location data
11
11
  log_level message]
12
+ MIN_COL_WIDTH = 14
12
13
 
13
14
  class ParseError < StandardError
14
15
  end
@@ -16,6 +17,7 @@ class Steno::JsonPrettifier
16
17
  def initialize(excluded_fields = [])
17
18
  @time_format = "%Y-%m-%d %H:%M:%S.%6N"
18
19
  @excluded_fields = Set.new(excluded_fields)
20
+ @max_src_len = MIN_COL_WIDTH
19
21
  end
20
22
 
21
23
  def prettify_line(line)
@@ -63,7 +65,8 @@ class Steno::JsonPrettifier
63
65
  end
64
66
 
65
67
  def format_source(record)
66
- "%14s" % record["source"]
68
+ @max_src_len = [@max_src_len, record["source"].length].max
69
+ record["source"].ljust(@max_src_len)
67
70
  end
68
71
 
69
72
  def format_process_id(record)
@@ -7,6 +7,8 @@ require "syslog"
7
7
  class Steno::Sink::Syslog < Steno::Sink::Base
8
8
  include Singleton
9
9
 
10
+ MAX_MESSAGE_SIZE = 1024 * 3
11
+
10
12
  LOG_LEVEL_MAP = {
11
13
  :fatal => Syslog::LOG_CRIT,
12
14
  :error => Syslog::LOG_ERR,
@@ -30,6 +32,7 @@ class Steno::Sink::Syslog < Steno::Sink::Base
30
32
  end
31
33
 
32
34
  def add_record(record)
35
+ record = truncate_record(record)
33
36
  msg = @codec.encode_record(record)
34
37
  pri = LOG_LEVEL_MAP[record.log_level.name]
35
38
  @syslog_lock.synchronize { @syslog.log(pri, "%s", msg) }
@@ -38,4 +41,16 @@ class Steno::Sink::Syslog < Steno::Sink::Base
38
41
  def flush
39
42
  nil
40
43
  end
44
+ private
45
+
46
+ def truncate_record(record)
47
+ return record if record.message.size <= MAX_MESSAGE_SIZE
48
+
49
+ truncated = record.message.slice(0..(MAX_MESSAGE_SIZE - 1))
50
+ truncated << "..."
51
+ Steno::Record.new(record.source, record.log_level,
52
+ truncated,
53
+ [record.file, record.lineno, record.method],
54
+ record.data)
55
+ end
41
56
  end
@@ -1,3 +1,3 @@
1
1
  module Steno
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -28,6 +28,42 @@ describe Steno::JsonPrettifier do
28
28
  prettified.should match(exp_regex)
29
29
  end
30
30
 
31
+ it "should always use the largest src len to determine src column width" do
32
+ test_srcs = [
33
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
34
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 1),
35
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH),
36
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 1),
37
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
38
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 3),
39
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 2),
40
+ 'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 2)
41
+ ]
42
+
43
+ regex = ['\d{4}-\d{2}-\d{2}', # YYYY-MM-DD
44
+ '\d{2}:\d{2}:\d{2}\.\d{6}', # HH:MM:SS.uS
45
+ '([a-zA-Z0-9\ ]+)', # Source (to be captured)
46
+ 'pid=\d+', # Process id
47
+ '.+' # Everything else
48
+ ].join("\s") + "\n"
49
+
50
+ max_src_len = Steno::JsonPrettifier::MIN_COL_WIDTH
51
+ test_srcs.each do |src|
52
+ record = Steno::Record.new(src,
53
+ :info,
54
+ "message",
55
+ ["filename", "line", "method"],
56
+ "test" => "data")
57
+
58
+ encoded = codec.encode_record(record)
59
+ prettified = prettifier.prettify_line(encoded)
60
+ src_col = prettified.match(regex)[1]
61
+
62
+ max_src_len = [max_src_len, src.length].max
63
+ src_col.length.should == max_src_len
64
+ end
65
+ end
66
+
31
67
  it "should raise a parse error when the json-encoded string is not a hash" do
32
68
  expect {
33
69
  prettifier.prettify_line("[1,2,3]")
@@ -23,4 +23,8 @@ describe Steno::Record do
23
23
  it "should stringify the message" do
24
24
  record.message.should be_a(String)
25
25
  end
26
+
27
+ it "should use a UTC timestamp" do
28
+ record.timestamp.to_f.should be_within(0.1).of(Time.now.utc.to_f)
29
+ end
26
30
  end
@@ -9,6 +9,11 @@ describe Steno::Sink::Syslog do
9
9
  Steno::Record.new("source", level, "message")
10
10
  end
11
11
 
12
+ let(:record_with_big_message) do
13
+ Steno::Record.new("source", level,
14
+ "a" * (Steno::Sink::Syslog::MAX_MESSAGE_SIZE + 1))
15
+ end
16
+
12
17
  describe "#add_record" do
13
18
  it "should append an encoded record with the correct priority" do
14
19
  identity = "test"
@@ -29,6 +34,35 @@ describe Steno::Sink::Syslog do
29
34
 
30
35
  sink.add_record(record)
31
36
  end
37
+
38
+ it "should truncate the record message if its greater than than allowed size" do
39
+ identity = "test"
40
+
41
+ syslog = mock("syslog")
42
+ Syslog.should_receive(:open) \
43
+ .with(identity, Syslog::LOG_PID, Syslog::LOG_USER) \
44
+ .and_return(syslog)
45
+
46
+ sink = Steno::Sink::Syslog.instance
47
+ sink.open(identity)
48
+
49
+ truncated = record_with_big_message.message.
50
+ slice(0..(Steno::Sink::Syslog::MAX_MESSAGE_SIZE) - 1)
51
+ truncated << "..."
52
+ codec = mock("codec")
53
+ codec.should_receive(:encode_record) do |*args|
54
+ args.size.should == 1
55
+ args[0].message.should == truncated
56
+
57
+ next args[0].message
58
+ end
59
+
60
+ sink.codec = codec
61
+
62
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "%s", truncated)
63
+
64
+ sink.add_record(record_with_big_message)
65
+ end
32
66
  end
33
67
 
34
68
  describe "#flush" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.20
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-08-31 00:00:00.000000000Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape
16
- requirement: &16549780 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16549780
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: yajl-ruby
27
- requirement: &16533020 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '1.0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *16533020
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: ci_reporter
38
- requirement: &16532600 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *16532600
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rack-test
49
- requirement: &16531900 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *16531900
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rake
60
- requirement: &16531220 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *16531220
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rspec
71
- requirement: &16530580 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *16530580
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: A thread-safe logging library designed to support multiple log destinations.
81
111
  email:
82
112
  - mpage@rbcon.com
@@ -85,47 +115,47 @@ executables:
85
115
  extensions: []
86
116
  extra_rdoc_files: []
87
117
  files:
118
+ - bin/steno-prettify
119
+ - lib/steno/codec/base.rb
120
+ - lib/steno/codec/json.rb
121
+ - lib/steno/codec.rb
122
+ - lib/steno/config.rb
123
+ - lib/steno/context.rb
124
+ - lib/steno/core_ext.rb
125
+ - lib/steno/errors.rb
126
+ - lib/steno/http_handler.rb
127
+ - lib/steno/json_prettifier.rb
128
+ - lib/steno/log_level.rb
129
+ - lib/steno/logger.rb
130
+ - lib/steno/record.rb
131
+ - lib/steno/sink/base.rb
132
+ - lib/steno/sink/io.rb
133
+ - lib/steno/sink/syslog.rb
134
+ - lib/steno/sink.rb
135
+ - lib/steno/tagged_logger.rb
136
+ - lib/steno/version.rb
137
+ - lib/steno.rb
138
+ - LICENSE
88
139
  - Rakefile
140
+ - README.md
141
+ - spec/spec_helper.rb
142
+ - spec/support/barrier.rb
89
143
  - spec/support/null_sink.rb
90
144
  - spec/support/shared_context_specs.rb
91
- - spec/support/barrier.rb
92
- - spec/spec_helper.rb
93
- - spec/unit/context_spec.rb
94
- - spec/unit/steno_spec.rb
95
- - spec/unit/json_prettifier_spec.rb
96
145
  - spec/unit/config_spec.rb
146
+ - spec/unit/context_spec.rb
97
147
  - spec/unit/core_ext_spec.rb
98
- - spec/unit/record_spec.rb
99
- - spec/unit/logger_spec.rb
100
- - spec/unit/log_level_spec.rb
101
148
  - spec/unit/http_handler_spec.rb
102
149
  - spec/unit/json_codec_spec.rb
103
- - spec/unit/sink/syslog_spec.rb
150
+ - spec/unit/json_prettifier_spec.rb
151
+ - spec/unit/log_level_spec.rb
152
+ - spec/unit/logger_spec.rb
153
+ - spec/unit/record_spec.rb
104
154
  - spec/unit/sink/io_spec.rb
155
+ - spec/unit/sink/syslog_spec.rb
156
+ - spec/unit/steno_spec.rb
105
157
  - spec/unit/tagged_logger_spec.rb
106
- - lib/steno/tagged_logger.rb
107
- - lib/steno/config.rb
108
- - lib/steno/codec.rb
109
- - lib/steno/logger.rb
110
- - lib/steno/context.rb
111
- - lib/steno/version.rb
112
- - lib/steno/log_level.rb
113
- - lib/steno/http_handler.rb
114
- - lib/steno/errors.rb
115
- - lib/steno/core_ext.rb
116
- - lib/steno/record.rb
117
- - lib/steno/sink.rb
118
- - lib/steno/json_prettifier.rb
119
- - lib/steno/sink/io.rb
120
- - lib/steno/sink/syslog.rb
121
- - lib/steno/sink/base.rb
122
- - lib/steno/codec/json.rb
123
- - lib/steno/codec/base.rb
124
- - lib/steno.rb
125
- - README.md
126
- - LICENSE
127
158
  - steno.gemspec
128
- - bin/steno-prettify
129
159
  homepage: http://www.cloudfoundry.org
130
160
  licenses: []
131
161
  post_install_message:
@@ -146,25 +176,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
176
  version: '0'
147
177
  requirements: []
148
178
  rubyforge_project:
149
- rubygems_version: 1.8.10
179
+ rubygems_version: 1.8.23
150
180
  signing_key:
151
181
  specification_version: 3
152
182
  summary: A logging library.
153
183
  test_files:
184
+ - spec/spec_helper.rb
185
+ - spec/support/barrier.rb
154
186
  - spec/support/null_sink.rb
155
187
  - spec/support/shared_context_specs.rb
156
- - spec/support/barrier.rb
157
- - spec/spec_helper.rb
158
- - spec/unit/context_spec.rb
159
- - spec/unit/steno_spec.rb
160
- - spec/unit/json_prettifier_spec.rb
161
188
  - spec/unit/config_spec.rb
189
+ - spec/unit/context_spec.rb
162
190
  - spec/unit/core_ext_spec.rb
163
- - spec/unit/record_spec.rb
164
- - spec/unit/logger_spec.rb
165
- - spec/unit/log_level_spec.rb
166
191
  - spec/unit/http_handler_spec.rb
167
192
  - spec/unit/json_codec_spec.rb
168
- - spec/unit/sink/syslog_spec.rb
193
+ - spec/unit/json_prettifier_spec.rb
194
+ - spec/unit/log_level_spec.rb
195
+ - spec/unit/logger_spec.rb
196
+ - spec/unit/record_spec.rb
169
197
  - spec/unit/sink/io_spec.rb
198
+ - spec/unit/sink/syslog_spec.rb
199
+ - spec/unit/steno_spec.rb
170
200
  - spec/unit/tagged_logger_spec.rb
201
+ has_rdoc: