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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7ebf769a9b7ffda8af122c0f39ccf931af0bf2a91f5009755f441ec4df9e3d1
4
- data.tar.gz: 5230ebd2a81295a96370c7e2915f59e9c45d75873a4cdf035f00b185d17f31be
3
+ metadata.gz: 674c0f92e94346d1accfabe2491837bd0b82b56e1efb92b982e7e33ab2f18202
4
+ data.tar.gz: 4ebfb336c218f0497e84a0194b862cf17fc398760e47f5ac4e15448ea6e881f2
5
5
  SHA512:
6
- metadata.gz: b6d144db8cfccda8ecc46ede21c1b7b5838cb31a208d667cfefa0a00c6696a4908fda101458235cd128f76ab276cbf5623e93159aba2b1ca7197bbdcc3baaa54
7
- data.tar.gz: 384158be6d4621ce55e5347dd69ace02b25444c4ff3f0e3e7cb389ea7fb736b478d6ff8d984c26c78e58ef9ecc9c9e4d603f2776f814d840b908f3e876bf0321
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
- [![Build Status](https://travis-ci.org/Yesware/yeti_logger.svg?branch=master)](https://travis-ci.org/Yesware/yeti_logger)
5
+ [![Ruby](https://github.com/Yesware/yeti_logger/actions/workflows/ruby.yml/badge.svg?branch=master)](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
@@ -1,3 +1,3 @@
1
1
  module YetiLogger
2
- VERSION = "3.2.0"
2
+ VERSION = "3.3.3"
3
3
  end
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 'active_support/core_ext/benchmark'
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.ms do
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,
@@ -1,3 +1,4 @@
1
+ require "active_support"
1
2
  require 'spec_helper.rb'
2
3
 
3
4
  # Class used for class and instance level testing
@@ -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.2.0
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: 2021-07-13 00:00:00.000000000 Z
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.1.6
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
@@ -1,18 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.0
5
- - 2.1
6
- - 2.2.2
7
- - 2.3.1
8
- - jruby-20mode
9
-
10
- script:
11
- - bundle exec rake ci
12
-
13
- sudo: false
14
-
15
- env:
16
- global:
17
- # To allow JRUBY to install c-extension gems
18
- - "JRUBY_OPTS=-Xcext.enabled=true"