yeti_logger 3.2.0 → 3.3.2

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: f58be8ecadfe9be95d8517795d6d28b68d3c870957f73477e9a9780c78089c9d
4
+ data.tar.gz: b693a3f73e811f9f2d773755d05339b083517bbf288dcb96cf7c2710819ce326
5
5
  SHA512:
6
- metadata.gz: b6d144db8cfccda8ecc46ede21c1b7b5838cb31a208d667cfefa0a00c6696a4908fda101458235cd128f76ab276cbf5623e93159aba2b1ca7197bbdcc3baaa54
7
- data.tar.gz: 384158be6d4621ce55e5347dd69ace02b25444c4ff3f0e3e7cb389ea7fb736b478d6ff8d984c26c78e58ef9ecc9c9e4d603f2776f814d840b908f3e876bf0321
6
+ metadata.gz: '010960813b5a5cabea56c2299a692a5111682a330262350bd68da570c435ca9a61cfcdf79ff66c20c18424a596179ea2423681d3acb42262ce35d61b4e3db45f'
7
+ data.tar.gz: 5f1a528a27bbc3b851c4980f3fe5af6c135a37874da3744c9a958488b351fa41e772725241204d87e61f4e946de96814defd08ddafa26e15ac9bdade103c5b3c
@@ -0,0 +1,32 @@
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
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
31
+ - name: Run tests
32
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # yeti_logger changelog
2
2
 
3
+ ## v3.3.2
4
+ - CustomFormatter does not include timestamp in log in production and staging environments
5
+
6
+ ## v3.3.1
7
+ - CustomFormatter uses Time.now instead of Time.now.utc
8
+
9
+ ## v3.3.0
10
+ - Add custom rails logger formatter
11
+
3
12
  ## v3.2.0
4
13
  - Added configuration to override debug logging for specific users
5
14
 
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,3 +1,3 @@
1
1
  module YetiLogger
2
- VERSION = "3.2.0"
2
+ VERSION = "3.3.2"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yesware, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -115,11 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/ruby.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
- - ".ruby-gemset"
121
- - ".ruby-version"
122
- - ".travis.yml"
123
121
  - CHANGELOG.md
124
122
  - Gemfile
125
123
  - MIT-LICENSE
@@ -128,6 +126,7 @@ files:
128
126
  - lib/yeti_logger.rb
129
127
  - lib/yeti_logger/configuration.rb
130
128
  - lib/yeti_logger/constants.rb
129
+ - lib/yeti_logger/custom_formatter.rb
131
130
  - lib/yeti_logger/message_formatters.rb
132
131
  - lib/yeti_logger/test_helper.rb
133
132
  - lib/yeti_logger/version.rb
@@ -157,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
156
  - !ruby/object:Gem::Version
158
157
  version: '0'
159
158
  requirements: []
160
- rubygems_version: 3.1.6
159
+ rubygems_version: 3.5.3
161
160
  signing_key:
162
161
  specification_version: 4
163
162
  summary: Provides standardized logging
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"