logist 0.1.4 → 0.2.0
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 +19 -0
- data/lib/logist/formatter/json.rb +21 -15
- data/lib/logist/logger.rb +10 -2
- data/lib/logist/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e6ad3e32e005fb5cd93ab69c54a65cda28d6c39339084d0d85ab0d506478cb8
|
4
|
+
data.tar.gz: fba3d6f1f25d24836fbe8bc63d0e45f7061001144b4b9b472898cda2dfc3e4ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d9c68a45b69f8a44f3416359582d60a3ad3b7cc6c2e801f76d9f3b5712a2afa40440d9220da527abfe8fa9582fcf810e4b2f6a01ee96bdf48925007e219b299
|
7
|
+
data.tar.gz: fbb266f39ea4f7175e1a55a683092944885a15152ad13bc790dfd3572140cb068f149fefee7814859547dbf93382347d0be660eb0321bb8e077cf7e6deb972e6
|
data/README.md
CHANGED
@@ -66,6 +66,25 @@ Rails.application.configure do
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
+
### flat_json option
|
70
|
+
|
71
|
+
If you want to log Hash object, but you don't want to have nested JSON, you can set `flat_json=true`:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
config.logger.formatter.flat_json = true
|
75
|
+
```
|
76
|
+
|
77
|
+
When `flat_json=false` (default):
|
78
|
+
|
79
|
+
```json
|
80
|
+
{"level":"INFO","message":{"foo":"bar"}}
|
81
|
+
```
|
82
|
+
|
83
|
+
When `flat_json=true`:
|
84
|
+
|
85
|
+
```json
|
86
|
+
{"level":"INFO","foo":"bar"}
|
87
|
+
```
|
69
88
|
|
70
89
|
|
71
90
|
## Development
|
@@ -5,23 +5,29 @@ require 'rails'
|
|
5
5
|
module Logist
|
6
6
|
module Formatter
|
7
7
|
class Json < ::Logger::Formatter
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
attr_accessor :flat_json
|
9
|
+
|
10
|
+
def call(severity, timestamp, progname, raw_msg)
|
11
|
+
msg = normalize_message(raw_msg)
|
12
|
+
payload = { level: severity, timestamp: format_datetime(timestamp), environment: ::Rails.env }
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
when "Array"
|
17
|
-
msg
|
18
|
-
else
|
19
|
-
begin
|
20
|
-
JSON.parse(msg)
|
21
|
-
rescue JSON::ParserError
|
22
|
-
"#{msg}"
|
23
|
-
end
|
14
|
+
if flat_json && msg.is_a?(Hash)
|
15
|
+
payload.merge!(msg)
|
16
|
+
else
|
17
|
+
payload.merge!(message: msg)
|
24
18
|
end
|
19
|
+
|
20
|
+
payload.to_json << "\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def normalize_message(raw_msg)
|
26
|
+
return raw_msg unless raw_msg.is_a?(String)
|
27
|
+
|
28
|
+
JSON.parse(raw_msg)
|
29
|
+
rescue JSON::ParserError
|
30
|
+
raw_msg
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
data/lib/logist/logger.rb
CHANGED
@@ -14,17 +14,25 @@ module Logist
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
|
17
|
-
progname: nil, formatter: nil, datetime_format: nil,
|
17
|
+
progname: nil, formatter: nil, datetime_format: nil, flat_json: false,
|
18
18
|
shift_period_suffix: '%Y%m%d')
|
19
19
|
# I think that Logist should support other formats in the future.
|
20
20
|
# But, as it is now, Logist only support json format.
|
21
21
|
# So this line force json format all environments.
|
22
22
|
@formatter = Logist::Formatter::Json.new
|
23
23
|
@formatter.datetime_format = datetime_format
|
24
|
+
@formatter.flat_json = flat_json
|
24
25
|
super(logdev, shift_age, shift_size, level: level,
|
25
26
|
progname: progname, formatter: @formatter, datetime_format: datetime_format,
|
26
27
|
shift_period_suffix: shift_period_suffix)
|
27
|
-
|
28
|
+
|
29
|
+
# https://github.com/rails/rails/pull/34055
|
30
|
+
# even with ^ respond_to?(:after_initialize) is still true
|
31
|
+
# but we know not to run it if ActiveSupport::LoggerSilence is defined, since that was added in the same rails version
|
32
|
+
# via https://github.com/rails/rails/pull/34045
|
33
|
+
if !defined?(ActiveSupport::LoggerSilence) && respond_to?(:after_initialize)
|
34
|
+
after_initialize
|
35
|
+
end
|
28
36
|
end
|
29
37
|
end
|
30
38
|
end
|
data/lib/logist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AkiraFukushima
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -128,7 +128,7 @@ licenses:
|
|
128
128
|
- MIT
|
129
129
|
metadata:
|
130
130
|
allowed_push_host: https://rubygems.org
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
146
|
+
rubygems_version: 3.1.2
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Change log format to json in Rails.
|
150
150
|
test_files: []
|