semantic_logger 4.2.1 → 4.2.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: 65aba46ee7052dc3653a61a40fad4d69aed81e97
4
- data.tar.gz: 2c7b49cb33e90874a966b9cadbbadf99bc4f4291
3
+ metadata.gz: 5e2a3fa7d0cba9f44c7a64abbc17d3fe77a10174
4
+ data.tar.gz: bca2b99107ef30043276c03b5ea09cacb4065129
5
5
  SHA512:
6
- metadata.gz: a2ef7fb0d78bdb3ecac1ff6d8ef6cef1bb4797a7a0ac55b2cfab4f057d8f7c2c16519b37863a6fc1d8e728277765c678824d8234e3cfdf733386cf7f5ddeb073
7
- data.tar.gz: e8df29aebb5e16b47fe87d530daf5f822c436ab18ddba47d682799ddb5c048041ce63841f1c6430987ca89e196f99853c48ecb38c8a9b2a0b65b8e3fbfae1d7a
6
+ metadata.gz: 4c5afd6c5af4110f7f63adbdce4fbd419c9c33c88522d3c3a36acc3d2335dacc0d34f79bdd2775f0b0eadb9cf4d6284b0c0cbe514011bd323b346e54ca0ae525
7
+ data.tar.gz: e7f2cbf6618aed0c38b10312dee1008b5eb4cf98809525826a2460c3003bb82816e043bde83dd9c56ccf9475e018e352f4cecfa14cd8674c305c3af44999ec38
@@ -34,7 +34,7 @@ module SemanticLogger
34
34
 
35
35
  # Process info
36
36
  def process_info
37
- hash[:pid] = $PROCESS_ID
37
+ hash[:pid] = $$
38
38
  hash[:thread] = log.thread_name
39
39
 
40
40
  file, line = log.file_name_and_line
@@ -149,7 +149,7 @@ module SemanticLogger
149
149
  if result.is_a?(String)
150
150
  message = message.nil? ? result : "#{message} -- #{result}"
151
151
  assign(message: message, payload: payload, exception: exception)
152
- elsif message.nil? && result.is_a?(Hash)
152
+ elsif message.nil? && result.is_a?(Hash) && [:message, :payload, :exception].any? { |k| result.key? k }
153
153
  assign(result)
154
154
  elsif payload&.respond_to?(:merge)
155
155
  assign(message: message, payload: payload.merge(result), exception: exception)
@@ -240,7 +240,7 @@ module SemanticLogger
240
240
  file, line = file_name_and_line(true)
241
241
  file_name = " #{file}:#{line}" if file
242
242
 
243
- "#{$PROCESS_ID}:#{format("%.#{thread_name_length}s", thread_name)}#{file_name}"
243
+ "#{$$}:#{format("%.#{thread_name_length}s", thread_name)}#{file_name}"
244
244
  end
245
245
 
246
246
  CALLER_REGEXP = /^(.*):(\d+).*/
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger
2
- VERSION = '4.2.1'.freeze
2
+ VERSION = '4.2.2'.freeze
3
3
  end
@@ -96,7 +96,7 @@ module Appender
96
96
 
97
97
  duration_str = log.duration ? " (#{format('%.1f', log.duration)}ms)" : ''
98
98
 
99
- "#{log.formatted_time} #{log.level.to_s.upcase} [#{$PROCESS_ID}:#{log.thread_name}] #{tags}#{log.name} -- #{message}#{duration_str}"
99
+ "#{log.formatted_time} #{log.level.to_s.upcase} [#{$$}:#{log.thread_name}] #{tags}#{log.name} -- #{message}#{duration_str}"
100
100
  end
101
101
  end
102
102
 
@@ -26,7 +26,7 @@ module Appender
26
26
  assert_equal 'info', h['level']
27
27
  assert_equal @message, h['message']
28
28
  assert_equal 'SemanticLogger::Appender::Kafka', h['name']
29
- assert_equal $PROCESS_ID, h['pid']
29
+ assert_equal $$, h['pid']
30
30
 
31
31
  assert_equal 'log_messages', options[:topic]
32
32
  end
@@ -29,7 +29,7 @@ module Appender
29
29
  assert_equal 'thread', document['thread']
30
30
  assert document['time'].is_a?(Time)
31
31
  assert_nil document['payload']
32
- assert_equal $PROCESS_ID, document['pid']
32
+ assert_equal $$, document['pid']
33
33
  assert_equal 'test', document['host']
34
34
  assert_equal 'test_application', document['application']
35
35
  end
@@ -45,7 +45,7 @@ module Appender
45
45
  assert payload = document['payload']
46
46
  assert_equal 12_345, payload['tracking_number'], payload
47
47
  assert_equal 'HSSKLEU@JDK767', payload['session_id']
48
- assert_equal $PROCESS_ID, document['pid']
48
+ assert_equal $$, document['pid']
49
49
  assert_equal 'test', document['host']
50
50
  assert_equal 'test_application', document['application']
51
51
  end
@@ -61,7 +61,7 @@ module Appender
61
61
  assert payload = document['payload']
62
62
  assert_equal 12_345, payload['tracking_number'], payload
63
63
  assert_equal 'HSSKLEU@JDK767', payload['session_id']
64
- assert_equal $PROCESS_ID, document['pid']
64
+ assert_equal $$, document['pid']
65
65
  assert_equal 'test', document['host']
66
66
  assert_equal 'test_application', document['application']
67
67
  end
@@ -74,7 +74,7 @@ module Appender
74
74
  assert_equal 'hello world', document['message']
75
75
  assert_equal 'thread', document['thread']
76
76
  assert document['time'].is_a?(Time)
77
- assert_equal $PROCESS_ID, document['pid']
77
+ assert_equal $$, document['pid']
78
78
  assert_equal 'test', document['host']
79
79
  assert_equal 'test_application', document['application']
80
80
  end
@@ -93,7 +93,7 @@ module Appender
93
93
  assert payload = document['payload']
94
94
  assert_equal 12_345, payload['tracking_number'], payload
95
95
  assert_equal 'HSSKLEU@JDK767', payload['session_id']
96
- assert_equal $PROCESS_ID, document['pid']
96
+ assert_equal $$, document['pid']
97
97
  assert_equal 'test', document['host'], document.ai
98
98
  assert_equal 'test_application', document['application']
99
99
  end
@@ -45,7 +45,7 @@ module Appender
45
45
  Syslog.stub(:open, nil) do
46
46
  Syslog.stub(:log, nil) do
47
47
  syslog_appender = SemanticLogger::Appender::Syslog.new
48
- syslog_appender.send(level, 'AppenderSyslogTest #{level.to_s} message')
48
+ syslog_appender.send(level, "AppenderSyslogTest #{level} message")
49
49
  end
50
50
  end
51
51
  end
@@ -131,7 +131,7 @@ module SemanticLogger
131
131
 
132
132
  describe 'call' do
133
133
  it 'returns minimal elements' do
134
- assert_equal "#{expected_time} #{color}D#{clear} [#{$PROCESS_ID}:#{Thread.current.name}] #{color}ColorTest#{clear}", formatter.call(log, nil)
134
+ assert_equal "#{expected_time} #{color}D#{clear} [#{$$}:#{Thread.current.name}] #{color}ColorTest#{clear}", formatter.call(log, nil)
135
135
  end
136
136
 
137
137
  it 'retuns all elements' do
@@ -143,7 +143,7 @@ module SemanticLogger
143
143
  log.backtrace = backtrace
144
144
  set_exception
145
145
  duration = SemanticLogger::Formatters::Base::PRECISION == 3 ? '1' : '1.346'
146
- str = "#{expected_time} #{color}D#{clear} [#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:35] [#{color}first#{clear}] [#{color}second#{clear}] [#{color}third#{clear}] {#{color}first: 1#{clear}, #{color}second: 2#{clear}, #{color}third: 3#{clear}} (#{bold}#{duration}ms#{clear}) #{color}ColorTest#{clear} -- Hello World -- #{{first: 1, second: 2, third: 3}.ai(multiline: false)} -- Exception: #{color}RuntimeError: Oh no#{clear}\n"
146
+ str = "#{expected_time} #{color}D#{clear} [#{$$}:#{Thread.current.name} default_test.rb:35] [#{color}first#{clear}] [#{color}second#{clear}] [#{color}third#{clear}] {#{color}first: 1#{clear}, #{color}second: 2#{clear}, #{color}third: 3#{clear}} (#{bold}#{duration}ms#{clear}) #{color}ColorTest#{clear} -- Hello World -- #{{first: 1, second: 2, third: 3}.ai(multiline: false)} -- Exception: #{color}RuntimeError: Oh no#{clear}\n"
147
147
  assert_equal str, formatter.call(log, nil).lines.first
148
148
  end
149
149
  end
@@ -70,13 +70,13 @@ module SemanticLogger
70
70
 
71
71
  describe 'process_info' do
72
72
  it 'logs pid and thread name' do
73
- assert_equal "[#{$PROCESS_ID}:#{Thread.current.name}]", formatter.process_info
73
+ assert_equal "[#{$$}:#{Thread.current.name}]", formatter.process_info
74
74
  end
75
75
 
76
76
  it 'logs pid, thread name, and file name' do
77
77
  set_exception
78
78
  log.backtrace = backtrace
79
- assert_equal "[#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:99]", formatter.process_info
79
+ assert_equal "[#{$$}:#{Thread.current.name} default_test.rb:99]", formatter.process_info
80
80
  end
81
81
  end
82
82
 
@@ -153,7 +153,7 @@ module SemanticLogger
153
153
 
154
154
  describe 'call' do
155
155
  it 'returns minimal elements' do
156
- assert_equal "#{expected_time} D [#{$PROCESS_ID}:#{Thread.current.name}] DefaultTest", formatter.call(log, nil)
156
+ assert_equal "#{expected_time} D [#{$$}:#{Thread.current.name}] DefaultTest", formatter.call(log, nil)
157
157
  end
158
158
 
159
159
  it 'retuns all elements' do
@@ -165,7 +165,7 @@ module SemanticLogger
165
165
  log.backtrace = backtrace
166
166
  set_exception
167
167
  duration = SemanticLogger::Formatters::Base::PRECISION == 3 ? '1' : '1.346'
168
- str = "#{expected_time} D [#{$PROCESS_ID}:#{Thread.current.name} default_test.rb:99] [first] [second] [third] {first: 1, second: 2, third: 3} (#{duration}ms) DefaultTest -- Hello World -- {:first=>1, :second=>2, :third=>3} -- Exception: RuntimeError: Oh no\n"
168
+ str = "#{expected_time} D [#{$$}:#{Thread.current.name} default_test.rb:99] [first] [second] [third] {first: 1, second: 2, third: 3} (#{duration}ms) DefaultTest -- Hello World -- {:first=>1, :second=>2, :third=>3} -- Exception: RuntimeError: Oh no\n"
169
169
  assert_equal str, formatter.call(log, nil).lines.first
170
170
  end
171
171
  end
data/test/logger_test.rb CHANGED
@@ -88,6 +88,13 @@ class LoggerTest < Minitest::Test
88
88
  assert_equal payload, log.payload
89
89
  end
90
90
 
91
+ it 'logs payload from block' do
92
+ logger.send(level) { { 'test_key1' => 'hello world', 'test_key2' => payload} }
93
+
94
+ assert log = log_message
95
+ assert_equal log.payload, { 'test_key1' => 'hello world', 'test_key2' => payload }
96
+ end
97
+
91
98
  it 'logs payload only' do
92
99
  logger.send(level, payload: payload)
93
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby