json_tagged_logger 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/json_tagged_logger/formatter.rb +11 -2
- data/lib/json_tagged_logger/log_tags_config.rb +6 -2
- data/lib/json_tagged_logger/logger.rb +3 -0
- data/lib/json_tagged_logger/tag_from_session.rb +2 -0
- data/lib/json_tagged_logger/version.rb +1 -1
- metadata +73 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde9c968aab725f59b4d0002b2e318b286edb8e8b7790222d1002e51ce631e6e
|
4
|
+
data.tar.gz: 97e23c6b02ec7faa8869659c59ef8ba1f2bc200cd607b4e248d2e8a7e74cab5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c21e9f1e126a80a8160587f04d30ca7ccd83433471e78c017320734d570f3cb43935e78bf8bd0a858d114c98fd2fc2115b45363f9e0e283d4c3d6ba182dd94e
|
7
|
+
data.tar.gz: be70dcda430a3341613c09c85eebcc66f98c9361658192808ab6fb9b0bd63b498713e8ff907fad6c6ce116dead29c302acb11c8bb51bf91edd5e8a6b3df880ab
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# JsonTaggedLogger
|
2
2
|
|
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
|
+
|
3
5
|
`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.
|
4
6
|
|
5
7
|
## Usage
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
module JsonTaggedLogger
|
2
5
|
class Formatter
|
3
6
|
def call(severity, _time, _progname, message)
|
@@ -10,7 +13,7 @@ module JsonTaggedLogger
|
|
10
13
|
json_tags.each { |t| log.merge!(t) }
|
11
14
|
|
12
15
|
if text_tags.present?
|
13
|
-
log[:tags] = text_tags
|
16
|
+
log[:tags] = text_tags.to_a
|
14
17
|
end
|
15
18
|
|
16
19
|
bare_message = message_without_tags(message)
|
@@ -21,8 +24,14 @@ module JsonTaggedLogger
|
|
21
24
|
parsed_message = bare_message
|
22
25
|
ensure
|
23
26
|
if parsed_message.is_a?(Hash)
|
24
|
-
|
27
|
+
parsed_message.symbolize_keys!
|
28
|
+
if log.has_key?(:tags) && parsed_message.has_key?(:tags)
|
29
|
+
parsed_message[:tags] = parsed_message[:tags] + log[:tags]
|
30
|
+
end
|
31
|
+
|
32
|
+
log.merge!(parsed_message)
|
25
33
|
else
|
34
|
+
#binding.irb
|
26
35
|
log.merge!(msg: parsed_message.strip)
|
27
36
|
end
|
28
37
|
end
|
@@ -1,13 +1,17 @@
|
|
1
|
+
require 'action_dispatch'
|
2
|
+
|
1
3
|
module JsonTaggedLogger
|
2
4
|
class LogTagsConfig
|
3
5
|
def self.generate(*tags)
|
4
6
|
tags.map do |tag|
|
5
|
-
if tag.is_a?(
|
7
|
+
if tag.is_a?(String)
|
8
|
+
tag
|
9
|
+
elsif tag.is_a?(Proc) && tag.arity == 1
|
6
10
|
tag
|
7
11
|
elsif tag.is_a?(Symbol) && ActionDispatch::Request.method_defined?(tag)
|
8
12
|
-> (request) { { tag => request.send(tag) }.to_json }
|
9
13
|
else
|
10
|
-
raise ArgumentError, "Only symbols that ActionDispatch::Request responds to or single-argument Procs allowed. You provided '#{tag.inspect}'."
|
14
|
+
raise ArgumentError, "Only strings, symbols that ActionDispatch::Request responds to or single-argument Procs allowed. You provided '#{tag.inspect}'."
|
11
15
|
end
|
12
16
|
end
|
13
17
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Santry
|
@@ -9,7 +9,77 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 1980-01-01 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '6.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '6.1'
|
13
83
|
description: Formatter for logging with ActiveSupport::TaggedLogging as JSON
|
14
84
|
email:
|
15
85
|
- sean@santry.us
|
@@ -38,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
108
|
requirements:
|
39
109
|
- - ">="
|
40
110
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
111
|
+
version: '2.7'
|
42
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
113
|
requirements:
|
44
114
|
- - ">="
|