chalk-log 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: rake test
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
+ gem.required_ruby_version = '>= 1.9.3'
19
20
  gem.add_dependency 'chalk-config'
20
21
  gem.add_dependency 'logging'
21
22
  gem.add_dependency 'lspace'
@@ -58,13 +58,12 @@ class Chalk::Log::Layout < ::Logging::Layout
58
58
  raise Chalk::Log::InvalidArguments.new("Invalid leftover arguments: #{data.inspect}")
59
59
  end
60
60
 
61
- id = action_id
62
61
  pid = Process.pid
63
62
 
64
63
  pretty_print(
65
64
  time: timestamp_prefix(time),
66
65
  level: Chalk::Log::LEVELS[level],
67
- action_id: id,
66
+ span: span.to_s,
68
67
  message: message,
69
68
  error: error,
70
69
  info: (info && info.merge(contextual_info || {})) || contextual_info,
@@ -74,7 +73,7 @@ class Chalk::Log::Layout < ::Logging::Layout
74
73
 
75
74
  def pretty_print(spec)
76
75
  message = build_message(spec[:message], spec[:info], spec[:error])
77
- message = tag(message, spec[:time], spec[:pid], spec[:action_id])
76
+ message = tag(message, spec[:time], spec[:pid], spec[:span])
78
77
  message
79
78
  end
80
79
 
@@ -153,23 +152,31 @@ class Chalk::Log::Layout < ::Logging::Layout
153
152
  dumped = JSON.generate(wrapped)
154
153
  end
155
154
 
156
- dumped[1...-1] # strip off the brackets we added while array-ifying
157
- end
155
+ res = dumped[1...-1] # strip off the brackets we added while array-ifying
156
+
157
+ # Bug 6566 in ruby 2.0 (but not 2.1) allows generate() to return an invalid
158
+ # string when given invalid unicode input. Manually check for it.
159
+ unless res.valid_encoding?
160
+ raise ArgumentError.new("invalid byte sequence in UTF-8")
161
+ end
158
162
 
159
- def action_id
160
- LSpace[:action_id]
163
+ res
161
164
  end
162
165
 
163
166
  def contextual_info
164
167
  LSpace[:'chalk.log.contextual_info']
165
168
  end
166
169
 
167
- def tag(message, time, pid, action_id)
170
+ def span
171
+ LSpace[:span] || LSpace[:action_id]
172
+ end
173
+
174
+ def tag(message, time, pid, span)
168
175
  return message unless configatron.chalk.log.tagging
169
176
 
170
177
  metadata = []
171
178
  metadata << pid if configatron.chalk.log.pid
172
- metadata << action_id if action_id
179
+ metadata << span if span.length > 0
173
180
  prefix = "[#{metadata.join('|')}] " if metadata.length > 0
174
181
 
175
182
  if configatron.chalk.log.timestamp
@@ -1,5 +1,5 @@
1
1
  module Chalk
2
2
  module Log
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -5,27 +5,40 @@ require 'chalk-log'
5
5
  module Critic::Functional
6
6
  class LogTest < Test
7
7
  def enable_timestamp
8
- configatron.chalk.log.stubs(:timestamp).returns(true)
8
+ configatron.unlock! do
9
+ configatron.chalk.log.timestamp = true
10
+ end
9
11
  end
10
12
 
11
13
  def disable_timestamp
12
- configatron.chalk.log.stubs(:timestamp).returns(false)
14
+ configatron.unlock! do
15
+ configatron.chalk.log.timestamp = false
16
+ end
13
17
  end
14
18
 
15
19
  def disable_pid
16
- configatron.chalk.log.stubs(:pid).returns(false)
20
+ configatron.unlock! do
21
+ configatron.chalk.log.pid = false
22
+ end
17
23
  end
18
24
 
19
25
  def disable_tagging
20
- configatron.chalk.log.stubs(:tagging).returns(false)
26
+ configatron.unlock! do
27
+ configatron.chalk.log.tagging = false
28
+ end
21
29
  end
22
30
 
23
31
  before do
24
32
  Chalk::Log.init
25
33
  Process.stubs(:pid).returns(9973)
34
+ configatron.temp_start
26
35
  disable_timestamp
27
36
  end
28
37
 
38
+ after do
39
+ configatron.temp_end
40
+ end
41
+
29
42
  class MyClass
30
43
  include Chalk::Log
31
44
  end
@@ -136,6 +149,34 @@ module Critic::Functional
136
149
  end
137
150
  end
138
151
 
152
+ it 'logs spans correctly' do
153
+ enable_timestamp
154
+ TestSpan = Struct.new(:action_id, :span_id, :parent_id) do
155
+ def to_s
156
+ sprintf("%s %s>%s",
157
+ action_id,
158
+ parent_id.to_s(16).rjust(16,'0'),
159
+ span_id.to_s(16).rjust(16,'0'))
160
+ end
161
+ end
162
+ LSpace.with(span: TestSpan.new("action", 0, 0)) do
163
+ rendered = layout(data: ["llamas"])
164
+ assert_equal('[1979-04-09 00:00:00.000000] [9973|action 0000000000000000>0000000000000000] llamas', rendered)
165
+ end
166
+ LSpace.with(span: TestSpan.new("action", 2, 0)) do
167
+ rendered = layout(data: ["llamas"])
168
+ assert_equal('[1979-04-09 00:00:00.000000] [9973|action 0000000000000000>0000000000000002] llamas', rendered)
169
+ end
170
+ LSpace.with(span: TestSpan.new("action", 0, 123)) do
171
+ rendered = layout(data: ["llamas"])
172
+ assert_equal('[1979-04-09 00:00:00.000000] [9973|action 000000000000007b>0000000000000000] llamas', rendered)
173
+ end
174
+ LSpace.with(span: TestSpan.new("action", 2, 123)) do
175
+ rendered = layout(data: ["llamas"])
176
+ assert_equal('[1979-04-09 00:00:00.000000] [9973|action 000000000000007b>0000000000000002] llamas', rendered)
177
+ end
178
+ end
179
+
139
180
  describe 'faults' do
140
181
  it 'shows an appropriate error if the invalid arguments are provided' do
141
182
  rendered = layout(data: ['foo', nil])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chalk-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2014-12-04 00:00:00.000000000 Z
12
+ date: 2015-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chalk-config
@@ -131,6 +131,7 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - .gitignore
134
+ - .travis.yml
134
135
  - Gemfile
135
136
  - History.txt
136
137
  - LICENSE.txt
@@ -144,7 +145,6 @@ files:
144
145
  - lib/chalk-log/logger.rb
145
146
  - lib/chalk-log/utils.rb
146
147
  - lib/chalk-log/version.rb
147
- - tddium.yml
148
148
  - test/_lib.rb
149
149
  - test/_lib/fake.rb
150
150
  - test/_lib/fake/event.rb
@@ -164,10 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - ! '>='
166
166
  - !ruby/object:Gem::Version
167
- version: '0'
168
- segments:
169
- - 0
170
- hash: -3360703599458620341
167
+ version: 1.9.3
171
168
  required_rubygems_version: !ruby/object:Gem::Requirement
172
169
  none: false
173
170
  requirements:
@@ -176,10 +173,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
173
  version: '0'
177
174
  segments:
178
175
  - 0
179
- hash: -3360703599458620341
176
+ hash: 3516609577492555280
180
177
  requirements: []
181
178
  rubyforge_project:
182
- rubygems_version: 1.8.25
179
+ rubygems_version: 1.8.23
183
180
  signing_key:
184
181
  specification_version: 3
185
182
  summary: Chalk::Log makes any class loggable. It provides a logger that can be used
data/tddium.yml DELETED
@@ -1,8 +0,0 @@
1
- :tddium:
2
- :ruby_version: ruby-1.9.3-p194
3
- :bundler_version: 1.3.5
4
- :test_pattern:
5
- - "test/wholesome/[^_]*.rb"
6
- - "test/unit/[^_]*.rb"
7
- - "test/integration/[^_]*.rb"
8
- - "test/functional/[^_]*.rb"