ltsv_logger_formatter 0.1.2 → 0.2.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 +13 -0
- data/lib/ltsv_logger_formatter/version.rb +1 -1
- data/lib/ltsv_logger_formatter.rb +8 -5
- data/ltsv_logger_formatter.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f3509008f39570486a2ca095a9fda0089d04538
|
4
|
+
data.tar.gz: 28349db60e3c890faba16d590cf41001ed8cebd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83052717caf9b195715ae8a3ff8c7ce430d7d8b716f1ef840ed62ad2a0ac757c6f0ebba95d7d63c71514d5be5f1f094eaab5769c34c00c085dd8fb660bea6a34
|
7
|
+
data.tar.gz: f64e90bc40e960d5145917ada21f8c843c8c6df21937ddb99331511070df44ed57687f42caf85518712a84faac020c291866966e5610ed7a59b8e2eb1a5b01b5
|
data/README.md
CHANGED
@@ -85,6 +85,19 @@ logger.info('progname') { { key: 'val' } }
|
|
85
85
|
# => test1:INFO test2:2016-10-03T00:45:52.073456 test3:progname key:val
|
86
86
|
```
|
87
87
|
|
88
|
+
### Filtering parameters ###
|
89
|
+
|
90
|
+
You can filter parameters using `filter` option.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'action_dispatch/http/parameter_filter'
|
94
|
+
filter = ActionDispatch::Http::ParameterFilter.new([/password/])
|
95
|
+
|
96
|
+
logger.formatter = LtsvLoggerFormatter.new(filter: filter)
|
97
|
+
logger.info(key: 'value', password: 'password')
|
98
|
+
# => level:INFO time:2016-11-01T01:19:51.754113 key:value password:[FILTERED]
|
99
|
+
```
|
100
|
+
|
88
101
|
## Dependency
|
89
102
|
|
90
103
|
This gem uses [LTSV gem](https://github.com/condor/ltsv/blob/master/ltsv.gemspec).
|
@@ -11,13 +11,16 @@ class LtsvLoggerFormatter < ::Logger::Formatter
|
|
11
11
|
# @param [Symbol] severity_key Optional, key for severity. Default is :level.
|
12
12
|
# @param [Symbol] time_key Optional, key for time. Default is :time.
|
13
13
|
# @param [Symbol] progname_key Optional, key for progname. Default is :progname.
|
14
|
+
# @param [Object] filter Optional, object which responds to #filter, e.g. ActionDispatch::Http::ParameterFilter.
|
15
|
+
# This object used to filter parameter in hash such as 'password'.
|
14
16
|
def initialize(datetime_format: '%Y-%m-%dT%H:%M:%S.%6N',
|
15
|
-
severity_key: :level, time_key: :time, progname_key: :progname)
|
17
|
+
severity_key: :level, time_key: :time, progname_key: :progname, filter: nil)
|
16
18
|
super()
|
17
19
|
self.datetime_format = datetime_format
|
18
20
|
@severity_key = severity_key
|
19
21
|
@time_key = time_key
|
20
22
|
@progname_key = progname_key
|
23
|
+
@filter = filter
|
21
24
|
end
|
22
25
|
|
23
26
|
# Return formatted string using arguments.
|
@@ -44,9 +47,9 @@ class LtsvLoggerFormatter < ::Logger::Formatter
|
|
44
47
|
private
|
45
48
|
|
46
49
|
def format_data(data)
|
47
|
-
if data.is_a? Exception
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
return { message: data.message, class: data.class, backtrace: Array(data.backtrace).join("\\n") } if data.is_a? Exception
|
51
|
+
return { message: data.to_s } unless data.respond_to?(:to_hash)
|
52
|
+
|
53
|
+
@filter ? @filter.filter(data.to_hash) : data.to_hash
|
51
54
|
end
|
52
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltsv_logger_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryu39
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ltsv
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: A simple logger formatter for logging in ltsv format.
|
70
84
|
email:
|
71
85
|
- dev.ryu39@gmail.com
|