yeti_logger 3.2.0 → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +31 -0
- data/.github/workflows/ruby.yml +34 -0
- data/CHANGELOG.md +12 -0
- data/README.md +13 -1
- data/lib/yeti_logger/custom_formatter.rb +34 -0
- data/lib/yeti_logger/message_formatters.rb +0 -9
- data/lib/yeti_logger/version.rb +1 -1
- data/lib/yeti_logger.rb +2 -4
- data/spec/lib/yeti_logger/message_formatters_spec.rb +1 -0
- data/spec/lib/yeti_logger_spec.rb +13 -0
- data/yeti_logger.gemspec +0 -1
- metadata +6 -23
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 674c0f92e94346d1accfabe2491837bd0b82b56e1efb92b982e7e33ab2f18202
|
|
4
|
+
data.tar.gz: 4ebfb336c218f0497e84a0194b862cf17fc398760e47f5ac4e15448ea6e881f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59517ffceea669788533d74d550ef975ef8b1d051f251e2bb0d452e14f12eec85ce5b06340d3038fcd3b39cd89295828e337f4006122896887c2c8666ca4d773
|
|
7
|
+
data.tar.gz: 4ed75834c5fcb6c3308f199f64cd7596b01ffb1b3025e5a023242aba66333b01b97f628954c743bed3ea84ada74359465fa71f972b8ecba3ff5d5926f355e141
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Ruby Gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
name: Build + Publish
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
packages: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v2
|
|
17
|
+
- name: Set up Ruby 3.4
|
|
18
|
+
uses: ruby/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
ruby-version: 3.4
|
|
21
|
+
|
|
22
|
+
- name: Publish to RubyGems
|
|
23
|
+
run: |
|
|
24
|
+
mkdir -p $HOME/.gem
|
|
25
|
+
touch $HOME/.gem/credentials
|
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
28
|
+
gem build *.gemspec
|
|
29
|
+
gem push *.gem
|
|
30
|
+
env:
|
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
|
@@ -0,0 +1,34 @@
|
|
|
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: Ruby
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
push:
|
|
14
|
+
branches: [ master ]
|
|
15
|
+
pull_request:
|
|
16
|
+
branches: [ master ]
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
test:
|
|
20
|
+
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
strategy:
|
|
23
|
+
matrix:
|
|
24
|
+
ruby-version: ['3.3', '3.4']
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v2
|
|
28
|
+
- name: Set up Ruby
|
|
29
|
+
uses: ruby/setup-ruby@v1
|
|
30
|
+
with:
|
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# yeti_logger changelog
|
|
2
2
|
|
|
3
|
+
## v3.3.3
|
|
4
|
+
- Replace deprecated `active_support/core_ext/benchmark` with Ruby's standard `Benchmark` library (fixes Rails 8.2 deprecation warning)
|
|
5
|
+
|
|
6
|
+
## v3.3.2
|
|
7
|
+
- CustomFormatter does not include timestamp in log in production and staging environments
|
|
8
|
+
|
|
9
|
+
## v3.3.1
|
|
10
|
+
- CustomFormatter uses Time.now instead of Time.now.utc
|
|
11
|
+
|
|
12
|
+
## v3.3.0
|
|
13
|
+
- Add custom rails logger formatter
|
|
14
|
+
|
|
3
15
|
## v3.2.0
|
|
4
16
|
- Added configuration to override debug logging for specific users
|
|
5
17
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Provides standardized logging across Yesware apps.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/Yesware/yeti_logger/actions/workflows/ruby.yml)
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
@@ -105,6 +106,17 @@ is a hash, then the exception in injected into the hash and printed as
|
|
|
105
106
|
additional `key=value` pairs. Classname, message and backtrace are included in
|
|
106
107
|
the message.
|
|
107
108
|
|
|
109
|
+
### Custom formatter
|
|
110
|
+
To add a set of tags to every log output by the underlying logger, initialize
|
|
111
|
+
`YetiLogger::CustomFormatter` and assign it to your logger's formatter. Pass a
|
|
112
|
+
hash to the initializer mapping the name of the tags to the proc that evaluates
|
|
113
|
+
to their value. The procs are evaluated lazily when the log generated.
|
|
114
|
+
|
|
115
|
+
Rails.logger.formatter = CustomFormatter.new({
|
|
116
|
+
"thread_id": -> { Thread.current.object_id.to_s(36) },
|
|
117
|
+
"trace_id": -> { OpenTelemetry::Trace.current_span ? OpenTelemetry::Trace.current_span.context.hex_trace_id : "0" },
|
|
118
|
+
})
|
|
119
|
+
|
|
108
120
|
### Nested Hashes
|
|
109
121
|
|
|
110
122
|
For hash logging, each key and value are converted to strings which means
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# CustomFormatter is a custom Rails log formatter.
|
|
2
|
+
# It has support for adding arbitrary tags to every log created by the Rails logger.
|
|
3
|
+
# Tag values are generated at log creation time.
|
|
4
|
+
class YetiLogger::CustomFormatter
|
|
5
|
+
# @param tags [Hash] - maps names of tags to procs that return their value.
|
|
6
|
+
def initialize(tags = {})
|
|
7
|
+
super()
|
|
8
|
+
@tags = tags
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @param tags [Hash] - maps names of tags to procs that return their value
|
|
12
|
+
def add_tags(tags)
|
|
13
|
+
@tags.merge!(tags)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param severity [String]
|
|
17
|
+
# @param time [Time] unused
|
|
18
|
+
# @param progname [String] unused
|
|
19
|
+
# @param msg [String] - log body
|
|
20
|
+
def call(severity, time, progname, msg)
|
|
21
|
+
timestamp = %w(production staging).include?(ENV['RAILS_ENV']) ? "" : "#{Time.now.iso8601(3)} "
|
|
22
|
+
pid = Process.pid
|
|
23
|
+
msg = msg.inspect unless msg.is_a?(String)
|
|
24
|
+
msg = "#{msg}\n" unless msg[-1] == ?\n
|
|
25
|
+
log_str = "#{timestamp}pid=#{pid}"
|
|
26
|
+
|
|
27
|
+
tag_str = @tags.map { |k, v|
|
|
28
|
+
value = v.call
|
|
29
|
+
"#{k}=#{value}" unless value.to_s.empty?
|
|
30
|
+
}.compact.join(' ')
|
|
31
|
+
|
|
32
|
+
"#{log_str}#{tag_str.empty? ? '' : ' ' + tag_str} [#{severity}] - #{msg}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
# require 'logger'
|
|
2
|
-
# require 'yeti_logger/version'
|
|
3
|
-
# require 'yeti_logger/configuration'
|
|
4
|
-
# require 'active_support/core_ext/benchmark'
|
|
5
|
-
# require 'active_support/concern'
|
|
6
|
-
# require 'active_support/core_ext/object/blank'
|
|
7
|
-
# require 'active_support/core_ext/object/try'
|
|
8
|
-
|
|
9
|
-
|
|
10
1
|
# Helper class used to format messages for logging. These can be used
|
|
11
2
|
# directly, but are more convenient when used via YetiLogger
|
|
12
3
|
module YetiLogger::MessageFormatters
|
data/lib/yeti_logger/version.rb
CHANGED
data/lib/yeti_logger.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'yeti_logger/constants'
|
|
|
4
4
|
require 'yeti_logger/configuration'
|
|
5
5
|
require 'yeti_logger/wrapped_logger'
|
|
6
6
|
require 'yeti_logger/message_formatters'
|
|
7
|
-
require '
|
|
7
|
+
require 'benchmark'
|
|
8
8
|
require 'active_support/concern'
|
|
9
9
|
require 'active_support/core_ext/object/blank'
|
|
10
10
|
require 'active_support/core_ext/object/try'
|
|
@@ -151,9 +151,7 @@ module YetiLogger
|
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
def log_time(action, level = :info)
|
|
154
|
-
ms = Benchmark.
|
|
155
|
-
yield
|
|
156
|
-
end
|
|
154
|
+
ms = Benchmark.realtime { yield } * 1000
|
|
157
155
|
YetiLogger.logger.send(level,
|
|
158
156
|
MessageFormatters.build_log_message(self.class.name,
|
|
159
157
|
{ action: action,
|
|
@@ -256,6 +256,19 @@ describe YetiLogger do
|
|
|
256
256
|
sleep 0.01
|
|
257
257
|
end
|
|
258
258
|
end
|
|
259
|
+
|
|
260
|
+
it "logs elapsed time in milliseconds" do
|
|
261
|
+
expect(YetiLogger.logger).to receive(:info) do |msg|
|
|
262
|
+
expect(msg).to match(/time_ms=\d+/)
|
|
263
|
+
# Verify it's roughly 100ms (with some tolerance for CI variance)
|
|
264
|
+
ms = msg.match(/time_ms=(\d+)/)[1].to_i
|
|
265
|
+
expect(ms).to be_between(80, 200)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
instance.log_time("query_db") do
|
|
269
|
+
sleep 0.1
|
|
270
|
+
end
|
|
271
|
+
end
|
|
259
272
|
end
|
|
260
273
|
|
|
261
274
|
describe '#as_logger' do
|
data/yeti_logger.gemspec
CHANGED
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
|
23
23
|
spec.add_development_dependency "rake"
|
|
24
24
|
spec.add_development_dependency "rspec"
|
|
25
25
|
spec.add_development_dependency "yard"
|
|
26
|
-
spec.add_development_dependency "kramdown"
|
|
27
26
|
spec.add_development_dependency "simplecov"
|
|
28
27
|
spec.add_development_dependency "byebug"
|
|
29
28
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yeti_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yesware, Inc
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -66,20 +65,6 @@ dependencies:
|
|
|
66
65
|
- - ">="
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: kramdown
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
68
|
- !ruby/object:Gem::Dependency
|
|
84
69
|
name: simplecov
|
|
85
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -115,11 +100,10 @@ executables: []
|
|
|
115
100
|
extensions: []
|
|
116
101
|
extra_rdoc_files: []
|
|
117
102
|
files:
|
|
103
|
+
- ".github/workflows/gem-push.yml"
|
|
104
|
+
- ".github/workflows/ruby.yml"
|
|
118
105
|
- ".gitignore"
|
|
119
106
|
- ".rspec"
|
|
120
|
-
- ".ruby-gemset"
|
|
121
|
-
- ".ruby-version"
|
|
122
|
-
- ".travis.yml"
|
|
123
107
|
- CHANGELOG.md
|
|
124
108
|
- Gemfile
|
|
125
109
|
- MIT-LICENSE
|
|
@@ -128,6 +112,7 @@ files:
|
|
|
128
112
|
- lib/yeti_logger.rb
|
|
129
113
|
- lib/yeti_logger/configuration.rb
|
|
130
114
|
- lib/yeti_logger/constants.rb
|
|
115
|
+
- lib/yeti_logger/custom_formatter.rb
|
|
131
116
|
- lib/yeti_logger/message_formatters.rb
|
|
132
117
|
- lib/yeti_logger/test_helper.rb
|
|
133
118
|
- lib/yeti_logger/version.rb
|
|
@@ -142,7 +127,6 @@ homepage: ''
|
|
|
142
127
|
licenses:
|
|
143
128
|
- MIT
|
|
144
129
|
metadata: {}
|
|
145
|
-
post_install_message:
|
|
146
130
|
rdoc_options: []
|
|
147
131
|
require_paths:
|
|
148
132
|
- lib
|
|
@@ -157,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
141
|
- !ruby/object:Gem::Version
|
|
158
142
|
version: '0'
|
|
159
143
|
requirements: []
|
|
160
|
-
rubygems_version: 3.
|
|
161
|
-
signing_key:
|
|
144
|
+
rubygems_version: 3.6.9
|
|
162
145
|
specification_version: 4
|
|
163
146
|
summary: Provides standardized logging
|
|
164
147
|
test_files:
|
data/.ruby-gemset
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
yesware
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ruby-2.7.3
|
data/.travis.yml
DELETED