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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c41a0f98815517b88de7ad4bc73fded258b43d9
4
- data.tar.gz: c9279c545852670f286b36e2726ebafb440f50d8
3
+ metadata.gz: 0f3509008f39570486a2ca095a9fda0089d04538
4
+ data.tar.gz: 28349db60e3c890faba16d590cf41001ed8cebd9
5
5
  SHA512:
6
- metadata.gz: 98bb9d37efa7cd04330d10a04e42d902d2d371bbe4a9d9be3bcd4f52ced75aa354654990b1e0c52cc86eef335f968ab56418c5e49b3a7a47ae4a4047627fc181
7
- data.tar.gz: db00857be73b9296d63121ba352f4bc1506c672ee7866046e46ab90d795497a87e0ca295d33ca3d54fa4eaa7cef2919b219351f9aee31d034fb8ba9c006eba5d
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).
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
2
 
3
3
  class LtsvLoggerFormatter < Logger::Formatter
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -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
- return { message: data.message, class: data.class, backtrace: (data.backtrace || []).join("\\n") } # \n cannot be used in LTSV, so use \\n in backtrace.
49
- end
50
- data.respond_to?(:to_hash) ? data.to_hash : { message: data.to_s }
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
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler', '~> 1.13'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'actionpack'
29
30
  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.1.2
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-09 00:00:00.000000000 Z
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