lorekeeper 1.11.1 → 2.1.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: bfcc3f33a2a846246a7e85d8c8c2730d1099bb0c41b80b86998ffd6beb5736a4
4
- data.tar.gz: 2e7b7f4a5e80c372ca5b17b4f961efa80bbd17e67713a075064c63659767bc2f
3
+ metadata.gz: b8a5d046cc9e67c4efda44b74aa45acd384a49d58b1ea710799ff072de7b0316
4
+ data.tar.gz: c095a976184d6456d2605fdebc25ed20e31b992672e066b892b08be201fe70c8
5
5
  SHA512:
6
- metadata.gz: fc4fa20700854b22f850129142a801ac56131e0f46e6f7ad74e69356821505715514c3b32041c58eaf3affa4dfe0ec951244e5e63222c26a08b115d9ecf8ea3f
7
- data.tar.gz: 8de40794309ff297adee1865243dbc856a6b6f687cef620af6807b5a582e2011b00ab822a948e870368b01bcce9ac0c3071eba9d7b95ce8a75c8451468cc4dfa
6
+ metadata.gz: 76c142c27abbae12ec4e5bde2262ea79f962f0e5aa9ac6074c04fdf7b84cdc3d5c62cdfdaae45874589d53300de2ddc961657562d9abffbbec8501575ae9f2d6
7
+ data.tar.gz: 3e86217440ba8269f05c1a1ec44bc4262067a9608ee7caab4a35cfc222a8870a2e7bfbb51dd275ea42ee7169cc033d79ee692dd469f5e16b9a21ae04af348803
@@ -0,0 +1,29 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
26
+ - name: Run tests
27
+ run: bundle exec rspec
28
+ - name: Run benchmark
29
+ run: bundle exec rake benchmark
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 2.1.0
2
+ * Modify SimpleLogger to properly log exceptions with named parameters
3
+
4
+ # 2.0.0
5
+ * Set `mode: :compat` in Oj.dump to stringify keys
6
+ * Support Ruby 3.1
7
+ * Drop support for Ruby < 2.5.0
8
+
9
+ # 1.12.0
10
+ * Remove ZipkinTracer information from stacktrace output
11
+ * Move CI to GitHub Actions
12
+
1
13
  # 1.11.1
2
14
  * Modify FastLogger#add to log progname as a message if no message and block are given
3
15
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lorekeeper
2
2
 
3
- [![Build Status](https://travis-ci.org/JordiPolo/lorekeeper.svg?branch=master)](https://travis-ci.org/JordiPolo/lorekeeper)
3
+ [![build](https://github.com/JordiPolo/lorekeeper/actions/workflows/build.yml/badge.svg)](https://github.com/JordiPolo/lorekeeper/actions/workflows/build.yml)
4
4
 
5
5
  LoreKeeper contains a highly optimized JSON logger. It outputs messages as JSON and let the users to add their own customized fields.
6
6
  When used without extra fields it outputs 20% faster than the standard Logger for messages not longer than one line of text.
@@ -141,7 +141,7 @@ Will output:
141
141
  }
142
142
  ```
143
143
 
144
- This method also accepts a custom message, data and log level.
144
+ This method also accepts a custom message, data and log level:
145
145
 
146
146
  ```ruby
147
147
  rescue => e
@@ -169,16 +169,30 @@ Will output:
169
169
  }
170
170
  ```
171
171
 
172
- Alternatively you can use named parameters:
172
+ Please note that due to the way Ruby 2.x automatically converts Hash objects to keyword arguments when they come last,
173
+ you need to explicitly use the `data` keyword argument when you don't pass any other argument afterwards:
173
174
 
174
175
 
176
+ ```ruby
177
+ logger.exception(e, "custom msg!", { some: { data: 123 } })
178
+ # => ArgumentError: unknown keyword: some
179
+
180
+ logger.exception(e, "custom msg!", data: { some: { data: 123 } })
181
+ # => works
182
+ ```
183
+
184
+ Ruby 3.x is unaffected by this issue since the conversion is [not done automatically anymore](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/).
185
+
186
+
187
+ The available keyword arguments are `message`, `data` and `level`. They can be used instead of the fixed arguments:
188
+
175
189
  ```ruby
176
190
  rescue => e
177
191
  logger.exception(e, message: "custom msg!", data: { some: { data: 123 } }, level: :warn)
178
192
  end
179
193
  ```
180
194
 
181
- This is specially useful when there is no custom message or data:
195
+ This is especially useful when there is no custom message or data:
182
196
 
183
197
  ```ruby
184
198
  rescue => e
@@ -98,7 +98,7 @@ module Lorekeeper
98
98
 
99
99
  # Some instrumentation libraries pollute the stacktrace and create a large output which may
100
100
  # cause problems with certain logging backends.
101
- # Hardcording newrelic and active_support/callbacks now here.
101
+ # Hardcording newrelic, active_support/callbacks and zipkin-tracer now here.
102
102
  # In the future if this list grows, we may make it configurable.
103
103
  def clean_backtrace(backtrace)
104
104
  @backtrace_cleaner&.clean(backtrace) || backtrace
@@ -121,7 +121,7 @@ module Lorekeeper
121
121
  EXCEPTION = 'exception'
122
122
  STACK = 'stack'
123
123
  DATA = 'data'
124
- BLACKLISTED_FINGERPRINT = %r{newrelic_rpm|active_support/callbacks.rb}.freeze
124
+ BLACKLISTED_FINGERPRINT = %r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer}.freeze
125
125
 
126
126
  def with_extra_fields(fields)
127
127
  state[:extra_fields] = fields
@@ -148,7 +148,7 @@ module Lorekeeper
148
148
  fields_to_log[TIMESTAMP] = Time.now.utc.strftime(DATE_FORMAT)
149
149
  fields_to_log[LEVEL] = SEVERITY_NAMES_MAP[severity]
150
150
 
151
- @iodevice.write(Oj.dump(fields_to_log) << "\n")
151
+ @iodevice.write(Oj.dump(fields_to_log, mode: :compat, cache_keys: true, cache_str: 5) << "\n")
152
152
  end
153
153
  end
154
154
  end
@@ -28,7 +28,7 @@ module Lorekeeper
28
28
  # \e[colorm sets a color \e[0m resets all properties
29
29
  def log_data(severity, message)
30
30
  color = SEVERITY_TO_COLOR_MAP[severity]
31
- @iodevice.write("\e[#{color}m#{message}\e[0m\n")
31
+ @iodevice.write("\e[#{color}m#{message.gsub('\n', "\n").gsub('\t', "\t")}\e[0m\n")
32
32
  end
33
33
 
34
34
  def inspect
@@ -43,16 +43,31 @@ module Lorekeeper
43
43
  end
44
44
  end
45
45
 
46
- def exception(exception, custom_message = nil, custom_data = nil, level = :error)
47
- log_level = METHOD_SEVERITY_MAP[level] || ERROR
46
+ # To not raise NoMethodError for the methods defined in JSONLogger
47
+ def current_fields(*); end
48
+ def state(*); end
49
+ def add_thread_unsafe_fields(*); end
50
+ def remove_thread_unsafe_fields(*); end
51
+ def add_fields(*); end
52
+ def remove_fields(*); end
53
+
54
+ def exception(exception, custom_message = nil, custom_data = nil, custom_level = :error,
55
+ message: nil, data: nil, level: nil)
56
+
57
+ param_level = level || custom_level
58
+ param_data = data || custom_data
59
+ param_message = message || custom_message
60
+
61
+ log_level = METHOD_SEVERITY_MAP[param_level] || ERROR
48
62
 
49
63
  if exception.is_a?(Exception)
50
- backtrace = exception.backtrace || []
51
- message = custom_message || exception.message
52
- log_data(log_level, "#{exception.class}: #{exception.message}; #{message}, data: #{backtrace.join("\n")}")
64
+ message = param_message || exception.message
65
+ backtrace = "\n\nstack:\n#{exception.backtrace.join("\n")}" if exception.backtrace
66
+ data = "\n\ndata:\n#{param_data}" if param_data
67
+ log_data(log_level, "#{exception.class}: #{exception.message}; #{message} #{backtrace} #{data}")
53
68
  else
54
69
  log_data(METHOD_SEVERITY_MAP[:warn], 'Logger exception called without exception class.')
55
- error_with_data("#{exception.class}: #{exception.inspect} #{custom_message}", custom_data)
70
+ error_with_data("#{exception.class}: #{exception.inspect} #{param_message}", param_data)
56
71
  end
57
72
  end
58
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lorekeeper
4
- VERSION = '1.11.1'
4
+ VERSION = '2.1.0'
5
5
  end
data/lorekeeper.gemspec CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.required_ruby_version = '>= 2.4.0'
23
+ spec.required_ruby_version = '>= 2.5.0'
24
24
 
25
- spec.add_dependency 'oj', '>= 3.4', '< 4.0'
25
+ spec.add_dependency 'oj', '>= 3.12', '< 4.0'
26
26
 
27
27
  spec.add_development_dependency 'activesupport', '>= 4.0'
28
28
  spec.add_development_dependency 'bundler', '>= 1.16', '< 3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorekeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-29 00:00:00.000000000 Z
11
+ date: 2022-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.4'
19
+ version: '3.12'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.4'
29
+ version: '3.12'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4.0'
@@ -183,10 +183,10 @@ executables: []
183
183
  extensions: []
184
184
  extra_rdoc_files: []
185
185
  files:
186
+ - ".github/workflows/build.yml"
186
187
  - ".gitignore"
187
188
  - ".rspec"
188
189
  - ".rubocop.yml"
189
- - ".travis.yml"
190
190
  - CHANGELOG.md
191
191
  - Gemfile
192
192
  - LICENSE.txt
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- version: 2.4.0
216
+ version: 2.5.0
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
-
4
- rvm:
5
- - 2.4.9
6
- - 2.5.8
7
- - 2.6.6
8
- - 2.7.2
9
- - 3.0.0
10
-
11
- script: bundle exec rspec