json_tagged_logger 0.7.0 → 0.8.1
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/README.md +1 -0
- data/lib/json_tagged_logger/formatter.rb +4 -1
- data/lib/json_tagged_logger/logger.rb +17 -3
- data/lib/json_tagged_logger/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48dce1179bda6aa327eb29098149e0239814e8b9b9b3a3ecc41ce25191c9e20f
|
4
|
+
data.tar.gz: c791ccfcc0426c7f25c5831caed2d2d1b18a0df875c3e07344f2d533c7122e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d18d26d9af57487a525265be64f87b67acb5f1cd63c708574a47012047e80c1efd9cd44f861204abcce150e75483de912eb1e42a0e3b026e016f8f4427e4e0fa
|
7
|
+
data.tar.gz: 7d82438c5036cdad595ead5af5605c63ecbb5ad61a0c946cbc36ced7f2cd9a68b5885c6c1dae5f75a8a3c658a8733b2eefb6ad33e03e9edb3687a8f0b15548ef
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# JsonTaggedLogger
|
2
2
|
|
3
3
|
[](https://github.com/santry/json_tagged_logger/actions/workflows/ci.yml)
|
4
|
+
[](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
|
8
|
-
|
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
|
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.
|
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: '
|
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: '
|
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: '
|
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: '
|
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.
|
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.
|
118
|
+
rubygems_version: 3.5.9
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: JSON Tagged Log Formatter
|