ezlog 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: 1c262ec657610e6e59eaa38fca73bfd01ef5c8e9107ad1d45d7fcd652fe202ad
4
- data.tar.gz: eb01c4eebdf823979a4184dfb2ef07b63e66f12e3bc65497714f1a94bb348a06
3
+ metadata.gz: a3448fa736b7d0c38391f77c299ca38185705c50bfb9a48230166b1bf95d5cea
4
+ data.tar.gz: 6334e6cfbca5a00b5c10d3c272533711613d556bf4d452176a055ba876dae8f9
5
5
  SHA512:
6
- metadata.gz: fdb2c08f48096b08524b8b40a9f88f868d2b376356d14b5d8bc7e45fa6b6f0cb412f95cc1a4a4be613d041ab518c1128be66871307b71503661e8ff86d7914a4
7
- data.tar.gz: 22341fd2d610f7e373dc2fa30eb02a9d2bab28bc140bc5c9f25ccaeff175684a7a93afd9f7b2ea948cf13ac956fbd146f7d272ef45d8e780aae3342b8cffb994
6
+ metadata.gz: faa9b4f39da472e3e353c8d2d0f95a36f08eae1ca631f0c1611907488da9fbd80dc3a330cde6f7f103056a34e7a0e72469e53580d36180b9119f3c5e96bc03bf
7
+ data.tar.gz: 24798f5e9e2d2308f443bc2c4a72612aab10e389599fa45ce8eea535bf68fb104f9da8c3c1a8f4ceda225215597ab7f85a1e314985841679376c40e5deebd06c
@@ -1,3 +1,14 @@
1
+ ### 0.7.0 (2020-03-11)
2
+
3
+ [Full Changelog](https://github.com/emartech/ezlog/compare/v0.6.0...v0.7.0)
4
+
5
+ * Features & enhancements
6
+ * Added the ability to configure parameter logging of the [Rails](https://rubyonrails.org/) access log.
7
+ By default, all parameters are logged under the key `params`. By turning on the `log_only_whitelisted_params`
8
+ config swith, you can make sure that only the parameters whose name is included in the `whitelisted_params`
9
+ config setting get logged under the `params` key. All parameters will still be logged, but serialized into a
10
+ single string under the `params_seralized` key, not creating a lot of noise under `params`.
11
+
1
12
  ### 0.6.0 (2019-11-29)
2
13
 
3
14
  [Full Changelog](https://github.com/emartech/ezlog/compare/v0.5.3...v0.6.0)
data/README.md CHANGED
@@ -46,6 +46,7 @@ At the moment Ezlog only support [Rails](https://rubyonrails.org/) apps. Non-Rai
46
46
  * Initializes the [Logging](https://github.com/TwP/logging) library
47
47
  * Configures [Rails](https://rubyonrails.org/)'s logging
48
48
  * Configures [Sidekiq](https://github.com/mperham/sidekiq) logging
49
+ * Configures [Sequel](https://sequel.jeremyevans.net/) logging
49
50
  * Configures [Rack::Timeout](https://github.com/heroku/rack-timeout) logging
50
51
  * Provides support for adding context information to log messages
51
52
  * Provides testing support for [RSpec](https://rspec.info/)
@@ -118,6 +119,21 @@ With Ezlog:
118
119
  {"logger":"AccessLog","timestamp":"2019-06-08T08:49:31+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75463,"environment":"development","request_id":"9a43631b-284c-4677-9d08-9c1cc5c7d3a7","duration_sec":0.031,"message":"GET /welcome?subsession_id=34ea8596f9764f475f81158667bc2654 - 200 (OK)","remote_ip":"127.0.0.1","method":"GET","path":"/welcome?subsession_id=34ea8596f9764f475f81158667bc2654","params":{"subsession_id":"34ea8596f9764f475f81158667bc2654","controller":"pages","action":"welcome"},"response_status_code":200}
119
120
  ```
120
121
 
122
+ By default, Ezlog logs all request parameters as a hash (JSON object) under the `params` key. This is very convenient
123
+ in a structured logging system and makes it easy to search for specific request parameter values e.g. in ElasticSearch
124
+ (should you happen to store your logs there). Unfortunately, in some cases - such as when handling large forms - this
125
+ can create quite a bit of noise and impact the searchability of your logs negatively. For this reason, you have the
126
+ option to restrict which parameters get logged by adding something like the following to your application's configuration:
127
+
128
+ ```ruby
129
+ config.ezlog.log_only_whitelisted_params = true # default is false
130
+ config.ezlog.whitelisted_params = [:action] # default is [:controller, :action]
131
+ ```
132
+
133
+ Using this configuration, Ezlog will only log the `action` parameter under the `params` key, but will still log
134
+ all parameters serialized into a single string under the key `params_serialized`. You won't lose any information,
135
+ but you can make sure that only the relevant parameters of your requests are searchable (and thus protect your logs).
136
+
121
137
  #### The log level
122
138
 
123
139
  The logger's log level is determined as follows (in order of precedence):
@@ -157,6 +173,18 @@ TestWorker.perform_async 42
157
173
  #=> {"logger":"Sidekiq","timestamp":"2019-05-12T10:38:12+02:00","level":"INFO","hostname":"MacbookPro.local","pid":75538,"jid":"abcdef1234567890","queue":"default","worker":"TestWorker","created_at":"2019-05-12 10:38:10 +0200","enqueued_at":"2019-05-12 10:38:10 +0200","run_count":1,"customer_id":42,"duration_sec":2.667,"message":"TestWorker finished"}
158
174
  ```
159
175
 
176
+ ### Configures Sequel logging
177
+
178
+ Ezlog adds a logging extension to [Sequel](https://sequel.jeremyevans.net/) that appends a logger to any newly opened
179
+ database connection. This logger is an instance of a [Logging](https://github.com/TwP/logging) logger by the name of
180
+ `Sequel`, behaving as described above. It also sets [Sequel](https://sequel.jeremyevans.net/)'s `sql_log_level` to `debug`.
181
+
182
+ This extension isn't enabled by default, because [Sequel](https://sequel.jeremyevans.net/) logging isn't necessarily
183
+ needed in every project. You can enable it by adding the following line to your application's configuration:
184
+ ```
185
+ config.ezlog.enable_sequel_logging = true
186
+ ```
187
+
160
188
  ### Configures Rack::Timeout logging
161
189
 
162
190
  [Rack::Timeout](https://github.com/heroku/rack-timeout) is a very useful tool for people running services on Heroku
@@ -3,9 +3,10 @@ module Ezlog
3
3
  class AccessLog
4
4
  include LogContextHelper
5
5
 
6
- def initialize(app, logger)
6
+ def initialize(app, logger, whitelisted_params)
7
7
  @app = app
8
8
  @logger = logger
9
+ @whitelisted_params = whitelisted_params&.map &:to_s
9
10
  end
10
11
 
11
12
  def call(env)
@@ -28,12 +29,24 @@ module Ezlog
28
29
  end
29
30
 
30
31
  def log_request(request, status)
31
- @logger.info message: '%s %s - %i (%s)' % [request.method, request.filtered_path, status, Rack::Utils::HTTP_STATUS_CODES[status]],
32
- remote_ip: request.remote_ip,
33
- method: request.method,
34
- path: request.filtered_path,
35
- params: request.filtered_parameters,
36
- response_status_code: status
32
+ message = {
33
+ message: '%s %s - %i (%s)' % [request.method, request.filtered_path, status, Rack::Utils::HTTP_STATUS_CODES[status]],
34
+ remote_ip: request.remote_ip,
35
+ method: request.method,
36
+ path: request.filtered_path,
37
+ params: params_to_log_in(request),
38
+ response_status_code: status
39
+ }
40
+ message.merge! params_serialized: request.filtered_parameters.inspect if @whitelisted_params
41
+ @logger.info message
42
+ end
43
+
44
+ def params_to_log_in(request)
45
+ if @whitelisted_params.nil?
46
+ request.filtered_parameters
47
+ else
48
+ request.filtered_parameters.slice *@whitelisted_params
49
+ end
37
50
  end
38
51
  end
39
52
  end
@@ -2,6 +2,8 @@ module Ezlog
2
2
  class Railtie < Rails::Railtie
3
3
  config.ezlog = ActiveSupport::OrderedOptions.new
4
4
  config.ezlog.enable_sequel_logging = false
5
+ config.ezlog.log_only_whitelisted_params = false
6
+ config.ezlog.whitelisted_params = [:controller, :action]
5
7
 
6
8
  initializer "ezlog.initialize" do
7
9
  require "ezlog/rails/extensions"
@@ -27,7 +29,7 @@ module Ezlog
27
29
  initializer 'ezlog.configure_rails_middlewares' do |app|
28
30
  app.config.middleware.insert_after ::ActionDispatch::RequestId, Ezlog::Rails::RequestLogContext
29
31
  app.config.middleware.delete ::Rails::Rack::Logger
30
- app.config.middleware.insert_before ::ActionDispatch::DebugExceptions, Ezlog::Rails::AccessLog, Ezlog.logger('AccessLog')
32
+ app.config.middleware.insert_before ::ActionDispatch::DebugExceptions, Ezlog::Rails::AccessLog, Ezlog.logger('AccessLog'), whitelisted_params(app)
31
33
  app.config.middleware.insert_after ::ActionDispatch::DebugExceptions, Ezlog::Rails::LogExceptions, Ezlog.logger('Application')
32
34
  end
33
35
 
@@ -60,5 +62,9 @@ module Ezlog
60
62
  def disable_rack_timeout_logging
61
63
  ::Rack::Timeout::Logger.logger = ::Logger.new(nil)
62
64
  end
65
+
66
+ def whitelisted_params(app)
67
+ app.config.ezlog.log_only_whitelisted_params ? app.config.ezlog.whitelisted_params : nil
68
+ end
63
69
  end
64
70
  end
@@ -23,7 +23,7 @@ RSpec::Matchers.define :include_log_message do |expected|
23
23
  def expected_messages_from(object)
24
24
  @expected_messages ||= case object
25
25
  when Hash
26
- object.map { |k, v| MultiJson.dump(k => v)[1...-1] }
26
+ object.map { |k, v| JSON.dump(k => v)[1...-1] }
27
27
  when String
28
28
  [object]
29
29
  else
@@ -1,3 +1,3 @@
1
1
  module Ezlog
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zoltan Ormandi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2020-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging