Rails Logs. How to hide in logs all params from a specific controller?

by Hugo V   Last Updated August 14, 2019 05:26 AM - source

I have a rails 6 app with a Update controller ready for accept JSON Post Requests:

class ProcessLogsController < ApplicationController
  #...

  # POST /process_logs.json
  def create
   # ... code to save the json in a database ...
  end

  #...
end

When a make a Post request with the JSON as a body...

curl -X POST \
  http://localhost:3000/process_logs.json \
  -H 'Content-Type: application/json' \
  -d '{
    "Time": "A UNIX timestamp",
    "Message": "Host Message could be very long, and may include secret info",
    "host": "My Hostname" 
}'

I got this in the Logs:

Started POST "/process_logs.json" for ::1 at 2019-08-13 20:16:37 -0500
Processing by ProcessLogsController#create as JSON
  Parameters: {"Time"=>"A UNIX timestamp", "Message"=>"[FILTERED]", "host"=>"My Hostname", "process_log"=>{"Time"=>"A UNIX timestamp", "Message"=>"[FILTERED]", "host"=>"My Hostname"}}
  Rendering text template
  Rendered text template (Duration: 0.2ms | Allocations: 1)
Completed 200 OK in 4ms (Views: 1.7ms | Allocations: 227)

The output is correct and expected, but I have this corncern with my log:

  • The Parameters (Line 3) it have the JSON request twice, one for the request.body and other for the process_log params.
  • This controller could have millions of request in a day. And coud have much more keys in the JSON post

So my question is...

Is any way to disable/hide the line Parameters on the log for this specific controller#action.

I don't want to set the level to :warn because I want to view the other info (Respose code etc..)

Tags : ruby-on-rails


Answers 1


actually you can turn off parameters wrapping to process_log in params. Look at the documentation for parameters wrapping https://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html

Btw if what you are saying is true, you should maybe think about how to make your logs less verbose. With millions of request per day you won't be able to follow this log anyway.

We are using https://github.com/roidrage/lograge for production log in our app. It is less verbose and everything is logged atomically to one long line. It cannot happen that one request starts logging in the middle of the different request (but I would hope rails figured out how to solve this).

edariedl
edariedl
August 14, 2019 05:24 AM

Related Questions



Rails Background Jobs running twice

Updated December 06, 2017 01:26 AM


render another controller action and filling form

Updated November 11, 2017 20:26 PM

Bootstrap Modal Plugin is not working properly

Updated December 03, 2018 20:26 PM