json_tagged_logger 0.7.0 → 0.8.1

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: c43ee559e53a24cf5c12cd1163c1fd8713d8351cd3e6cc6b175dd92fd840a9de
4
- data.tar.gz: a0a1683625c7fd6342974f4f00c53820c61d26a703110a61becafee2bf5f1b76
3
+ metadata.gz: 48dce1179bda6aa327eb29098149e0239814e8b9b9b3a3ecc41ce25191c9e20f
4
+ data.tar.gz: c791ccfcc0426c7f25c5831caed2d2d1b18a0df875c3e07344f2d533c7122e05
5
5
  SHA512:
6
- metadata.gz: 6610c361726d1c670a35b6c92a6926995bddeb674fd4f1e19d7372fcb0b22d6c0de601b3681d9236c1764c6ae1ebebe56a6d0e144cc85442ea54712b0122d978
7
- data.tar.gz: ef5fcd7fe3cbb1ca07ca8bb8e0e4b90b25092f1c6ecd261a1bd39670bd997a1847cbc8071513e57ae4b59cfb9b9069c1ab26863030677d840eb80b4517a54b0a
6
+ metadata.gz: d18d26d9af57487a525265be64f87b67acb5f1cd63c708574a47012047e80c1efd9cd44f861204abcce150e75483de912eb1e42a0e3b026e016f8f4427e4e0fa
7
+ data.tar.gz: 7d82438c5036cdad595ead5af5605c63ecbb5ad61a0c946cbc36ced7f2cd9a68b5885c6c1dae5f75a8a3c658a8733b2eefb6ad33e03e9edb3687a8f0b15548ef
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # JsonTaggedLogger
2
2
 
3
3
  [![Build Status](https://github.com/santry/json_tagged_logger/actions/workflows/ci.yml/badge.svg)](https://github.com/santry/json_tagged_logger/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/json_tagged_logger.svg)](https://badge.fury.io/rb/json_tagged_logger)
4
5
 
5
6
  `JsonTaggedLogger` works in conjunction with [`ActiveSupport::TaggedLogging`](https://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html) and (optionally) [Lograge](https://github.com/roidrage/lograge) to produce JSON-formatted log output. By itself, `ActiveSupport::TaggedLogging` supports simple tagging. With `JsonTaggedLogger`, you can compose key/value pairs, simple tags, and the log message itself into a single JSON document for easy consumption and parsing in log aggregators.
6
7
 
@@ -1,8 +1,11 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/hash/keys'
2
3
  require 'json'
3
4
 
4
5
  module JsonTaggedLogger
5
6
  class Formatter
7
+ include ActiveSupport::TaggedLogging::Formatter
8
+
6
9
  attr_accessor :pretty_print
7
10
 
8
11
  def initialize(pretty_print: false)
@@ -22,7 +25,7 @@ module JsonTaggedLogger
22
25
  log[:tags] = text_tags.to_a
23
26
  end
24
27
 
25
- bare_message = message_without_tags(message)
28
+ bare_message = message_without_tags(message.to_s)
26
29
 
27
30
  begin
28
31
  parsed_message = JSON.parse(bare_message)
@@ -1,11 +1,25 @@
1
1
  require 'active_support'
2
- require 'active_support/tagged_logging'
3
2
 
4
3
  module JsonTaggedLogger
5
4
  module Logger
6
5
  def self.new(logger, pretty_print: false)
7
- logger.formatter = Formatter.new(pretty_print: pretty_print)
8
- ActiveSupport::TaggedLogging.new(logger)
6
+ logger = logger.clone
7
+ logger.formatter = JsonTaggedLogger::Formatter.new(pretty_print: pretty_print)
8
+ logger.extend(self)
9
9
  end
10
+
11
+ delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
12
+
13
+ def tagged(*tags)
14
+ if block_given?
15
+ formatter.tagged(*tags) { yield self }
16
+ else
17
+ logger = JsonTaggedLogger::Logger.new(self)
18
+ logger.formatter = JsonTaggedLogger::Formatter.new
19
+ logger.push_tags(*formatter.current_tags, *tags)
20
+ logger
21
+ end
22
+ end
23
+
10
24
  end
11
25
  end
@@ -1,3 +1,3 @@
1
1
  module JsonTaggedLogger
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_tagged_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Santry
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '6.1'
61
+ version: '5.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '6.1'
68
+ version: '5.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: actionpack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '6.1'
75
+ version: '5.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '6.1'
82
+ version: '5.2'
83
83
  description: Formatter for logging with ActiveSupport::TaggedLogging as JSON
84
84
  email:
85
85
  - sean@santry.us
@@ -108,14 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: '2.7'
111
+ version: '2.6'
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.5.6
118
+ rubygems_version: 3.5.9
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: JSON Tagged Log Formatter