semantic_logger 4.4.0 → 4.5.0

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
  SHA256:
3
- metadata.gz: 88a1f36f6ef4d857e13b696e283f6bbd643329a0ca7f3fd9ac4c9ef1e670aaae
4
- data.tar.gz: 01a175a96d750f9692bb28512d914434e442336c68eadd9f7b9f409a4d2f4a2b
3
+ metadata.gz: 34b3b78799e196b270d81aba7deb9b0accd1187a900967a3943dd03301c63199
4
+ data.tar.gz: 775b6eeca4ca6b9c38e9213e7f32fee9d179ce36148433dfa91a8630f74873b3
5
5
  SHA512:
6
- metadata.gz: e06dd57a7ee95bfc5aea5d4b2948101a1fbdb00dd76ac1b9ac0b68a4a3f666670b227d559451d4137e510d1c63b9ec9bd8f99326bfe765f9a610294221c2259f
7
- data.tar.gz: 0e2b66a5da5f5e2d21c185555f3502e7982d8d197ec9bade63092acae1750dcf1d8191de71dc8fbe0598d844b2c5f85931c407030a599260f41ad35470802a14
6
+ metadata.gz: 7cda8a50c62a2dcdb079d5f96cbde61e5cc941c443122a3bbc102a1513bc3686d44a20cca28e7627444bf640a6329035aefc43cb6111a3e6b9cb91411fe33782
7
+ data.tar.gz: caf355bf16e08b133fe07ddd6b4cab813b6e7224b3e1f152e1ab54cf30f574fc8665f99ae3938078fb35fcfeea3643d565a814cbe2774d263135c93722147b06
data/README.md CHANGED
@@ -11,6 +11,16 @@ Semantic Logger is a feature rich logging framework, and replacement for existin
11
11
 
12
12
  [Reference Documentation](http://www.rubydoc.info/gems/semantic_logger/)
13
13
 
14
+ ## Upgrading to Semantic Logger v4.4
15
+
16
+ With some forking frameworks it is necessary to call `reopen` after the fork. With v4.4 the
17
+ workaround for Ruby 2.5 crashes is no longer needed.
18
+ I.e. Please remove the following line if being called anywhere:
19
+
20
+ ~~~ruby
21
+ SemanticLogger::Processor.instance.instance_variable_set(:@queue, Queue.new)
22
+ ~~~
23
+
14
24
  ## Logging Destinations
15
25
 
16
26
  Logging to the following destinations are all supported "out-of-the-box":
@@ -70,7 +80,7 @@ The following changes need to be made when upgrading to V4:
70
80
  - Replace calls to Logger#with_payload with SemanticLogger.named_tagged.
71
81
  - Replace calls to Logger#payload with SemanticLogger.named_tags.
72
82
  - MongoDB Appender requires Mongo Ruby Client V2 or greater.
73
- - Appenders now write payload data in a seperate :payload tag instead of mixing them.
83
+ - Appenders now write payload data in a seperate :payload tag instead of mixing them
74
84
  directly into the root elements to avoid name clashes.
75
85
 
76
86
  As a result any calls like the following:
@@ -17,7 +17,7 @@ require 'date'
17
17
  module SemanticLogger
18
18
  module Appender
19
19
  class Elasticsearch < SemanticLogger::Subscriber
20
- attr_accessor :url, :index, :type, :client, :flush_interval, :timeout_interval, :batch_size, :elasticsearch_args
20
+ attr_accessor :url, :index, :date_pattern, :type, :client, :flush_interval, :timeout_interval, :batch_size, :elasticsearch_args
21
21
 
22
22
  # Create Elasticsearch appender over persistent HTTP(S)
23
23
  #
@@ -28,6 +28,11 @@ module SemanticLogger
28
28
  # I.e. The final index will look like 'semantic_logger-YYYY.MM.DD'
29
29
  # Default: 'semantic_logger'
30
30
  #
31
+ # date_pattern: [String]
32
+ # The time format used to generate the full index name. Useful
33
+ # if you want monthly indexes ('%Y.%m') or weekly ('%Y.%W').
34
+ # Default: '%Y.%m.%d'
35
+ #
31
36
  # type: [String]
32
37
  # Document type to associate with logs when they are written.
33
38
  # Default: 'log'
@@ -120,6 +125,7 @@ module SemanticLogger
120
125
  # Default: 'GET'
121
126
  def initialize(url: 'http://localhost:9200',
122
127
  index: 'semantic_logger',
128
+ date_pattern: '%Y.%m.%d',
123
129
  type: 'log',
124
130
  level: nil,
125
131
  formatter: nil,
@@ -132,6 +138,7 @@ module SemanticLogger
132
138
 
133
139
  @url = url
134
140
  @index = index
141
+ @date_pattern = date_pattern
135
142
  @type = type
136
143
  @elasticsearch_args = elasticsearch_args.dup
137
144
  @elasticsearch_args[:url] = url if url && !elasticsearch_args[:hosts]
@@ -173,8 +180,8 @@ module SemanticLogger
173
180
  end
174
181
 
175
182
  def bulk_index(log)
176
- daily_index = log.time.strftime("#{index}-%Y.%m.%d")
177
- {'index' => {'_index' => daily_index, '_type' => type}}
183
+ expanded_index_name = log.time.strftime("#{index}-#{date_pattern}")
184
+ {'index' => {'_index' => expanded_index_name, '_type' => type}}
178
185
  end
179
186
 
180
187
  def default_formatter
@@ -170,10 +170,10 @@ module SemanticLogger
170
170
  method = ::Syslog.opened? ? :reopen : :open
171
171
  ::Syslog.send(method, application, options, facility)
172
172
  when :tcp
173
- # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
174
- @tcp_client_options[:logger] = logger
175
173
  @tcp_client_options[:server] = "#{@server}:#{@port}"
176
174
  @remote_syslog = Net::TCPClient.new(@tcp_client_options)
175
+ # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
176
+ @remote_syslog.logger = logger
177
177
  when :udp
178
178
  @remote_syslog = UDPSocket.new
179
179
  else
@@ -43,7 +43,7 @@ module SemanticLogger
43
43
  logger.trace "Closing appender: #{appender.name}"
44
44
  appender.flush
45
45
  appender.close
46
- appenders.delete(appender)
46
+ delete(appender)
47
47
  rescue Exception => exc
48
48
  logger.error "Failed to close appender: #{appender.inspect}", exc
49
49
  end
@@ -341,7 +341,7 @@ module SemanticLogger
341
341
  params = message
342
342
  message = nil
343
343
  end
344
- start = Time.now
344
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
345
345
  begin
346
346
  if block_given?
347
347
  result =
@@ -362,7 +362,7 @@ module SemanticLogger
362
362
  message = params[:message] if params[:message]
363
363
  duration =
364
364
  if block_given?
365
- 1000.0 * (Time.now - start)
365
+ 1_000.0 * (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start)
366
366
  else
367
367
  params[:duration] || raise('Mandatory block missing when :duration option is not supplied')
368
368
  end
@@ -401,7 +401,7 @@ module SemanticLogger
401
401
 
402
402
  # Ignores filter, silence, payload
403
403
  exception = nil
404
- start = Time.now
404
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
405
405
  begin
406
406
  yield
407
407
  rescue Exception => exc
@@ -414,7 +414,7 @@ module SemanticLogger
414
414
  min_duration: min_duration,
415
415
  exception: exception,
416
416
  metric: metric,
417
- duration: 1000.0 * (Time.now - start),
417
+ duration: 1_000.0 * (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start),
418
418
  log_exception: log_exception,
419
419
  on_exception_level: on_exception_level
420
420
  )
@@ -44,8 +44,20 @@ module SemanticLogger
44
44
  # SemanticLogger.add_appender(io: $stdout, formatter: :color)
45
45
  #
46
46
  # Example:
47
- # # Use a colorized output logger chenging the color for info to green.
48
- # SemanticLogger.add_appender(io: $stdout, formatter: :color, color_map: {info: SemanticLogger::AnsiColors::YELLOW})
47
+ # # Use a colorized output logger changing the color for info to yellow.
48
+ # SemanticLogger.add_appender(io: $stdout, formatter: {color: {color_map: {info: SemanticLogger::AnsiColors::YELLOW}}})
49
+ #
50
+ # Example:
51
+ # # Override the Awesome Print options to output hashes over multiple lines:
52
+ # SemanticLogger.add_appender(io: $stdout, formatter: {color: {ap: {multiline: true}}})
53
+ #
54
+ # # Calling the appender added above:
55
+ # SemanticLogger['Test'].info('hi', {a: 1, b: 2})
56
+ # => true
57
+ # => 2019-02-12 11:47:50.794339 I [35832:70112015269920] Test -- hi -- {
58
+ # :a => 1,
59
+ # :b => 2
60
+ # }
49
61
  #
50
62
  # Parameters:
51
63
  # ap: [Hash]
@@ -4,26 +4,22 @@ module SemanticLogger
4
4
  # On completion the time it took to run the test is also logged.
5
5
  #
6
6
  # For example, add the following lines to `test_helper.rb`:
7
+ # require 'minitest/reporters'
8
+ #
7
9
  # reporters = [
8
10
  # Minitest::Reporters::ProgressReporter.new,
9
11
  # SemanticLogger::Reporters::Minitest.new
10
12
  # ]
11
13
  # Minitest::Reporters.use!(reporters)
12
14
  #
13
- # Log entries similar to the following should show up in the log file:
15
+ # And add `gem minitest-reporters` to the Gemfile.
14
16
  #
15
- # 2019-01-30 14:41:21.590383 I [9989:70268303433760] (9.958ms) Minitest -- Passed: test_0002_infinite timeout
16
- # 2019-01-30 14:41:21.590951 I [9989:70268303433760] Minitest -- Started: test_0002_must return the servers in the supplied order
17
- # 2019-01-30 14:41:21.592012 I [9989:70268303433760] (1.019ms) Minitest -- Passed: test_0002_must return the servers in the supplied order
18
- # 2019-01-30 14:41:21.592054 I [9989:70268303433760] Minitest -- Started: test_0003_must handle an empty list of servers
19
- # 2019-01-30 14:41:21.592094 I [9989:70268303433760] (0.014ms) Minitest -- Passed: test_0003_must handle an empty list of servers
20
- # 2019-01-30 14:41:21.592118 I [9989:70268303433760] Minitest -- Started: test_0001_must return one server, once
21
- # 2019-01-30 14:41:21.592510 I [9989:70268303433760] (0.361ms) Minitest -- Passed: test_0001_must return one server, once
17
+ # Log entries similar to the following should show up in the log file:
22
18
  #
23
- # Note:
24
- # - To use `Minitest::Reporters::ProgressReporter` the gem `minitest-reporters` is required, as well as the
25
- # following line in `test_helper.rb`:
26
- # `require 'minitest/reporters'`
19
+ # 2019-02-06 18:58:17.522467 I [84730:70256441962000] Minitest -- START RocketJob::DirmonEntry::with valid entry::#archive_file test_0001_moves file to archive dir
20
+ # 2019-02-06 18:58:17.527492 I [84730:70256441962000] (4.980ms) Minitest -- PASS RocketJob::DirmonEntry::with valid entry::#archive_file test_0001_moves file to archive dir
21
+ # 2019-02-06 18:58:17.527835 I [84730:70256441962000] Minitest -- START RocketJob::DirmonEntry::#job_class::with a valid job_class_name test_0001_return job class
22
+ # 2019-02-06 18:58:17.529761 I [84730:70256441962000] (1.882ms) Minitest -- PASS RocketJob::DirmonEntry::#job_class::with a valid job_class_name test_0001_return job class
27
23
  class Minitest < ::Minitest::AbstractReporter
28
24
  include SemanticLogger::Loggable
29
25
 
@@ -32,16 +28,16 @@ module SemanticLogger
32
28
  attr_accessor :io
33
29
 
34
30
  def before_test(test)
35
- logger.info('START', name: test.name)
31
+ logger.info("START #{test.class_name} #{test.name}")
36
32
  end
37
33
 
38
34
  def after_test(test)
39
35
  if test.error?
40
- logger.benchmark_error('FAIL', payload: {name: test.name}, duration: test.time * 1_000, metric: 'minitest/fail')
36
+ logger.benchmark_error("FAIL #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/fail')
41
37
  elsif test.skipped?
42
- logger.benchmark_warn('SKIP', payload: {name: test.name}, duration: test.time * 1_000, metric: 'minitest/skip')
38
+ logger.benchmark_warn("SKIP #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/skip')
43
39
  else
44
- logger.benchmark_info('PASS', payload: {name: test.name}, duration: test.time * 1_000, metric: 'minitest/pass')
40
+ logger.benchmark_info("PASS #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/pass')
45
41
  end
46
42
  end
47
43
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger
2
- VERSION = '4.4.0'.freeze
2
+ VERSION = '4.5.0'.freeze
3
3
  end
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.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-03 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby