1

For GDPR-reasons I would like to remove IP-addresses in my logs as I have no use of that information, and thus it is not necessary to keep them.

  • Rails v 4.2.10
  • Ruby v 2.4.7

Is there an easy way of filtering the IP-addresses in the log file or at least replace them? I am specifically interested in this line:

Started GET "/" for xx.xxx.xxx.x at 2020-05-11 14:14:30 +0000

where xx.xxx.xxx.x is an actual IP number.

Christoffer
  • 2,271
  • 3
  • 26
  • 57
  • take a look at https://stackoverflow.com/questions/22705823/disable-ip-address-logging-rails – mr_sudaca May 12 '20 at 14:52
  • Thanks, I should have mentioned I have checked that one out before. It seems overly complicated and, frankly, I have no idea what it actually does. I would expect something far simpler for a task like this (such as how passwords can be filtered). – Christoffer May 14 '20 at 09:41

1 Answers1

0

maybe you can just monkey patch the logger class so I doesn't append the ip to the log message:

module Rails
  module Rack
    class Logger
      def started_request_message(request) # :doc:
        'Started %s "%s" for %s at %s' % [
          request.request_method,
          request.filtered_path,
          'xx.xxx.xxx.x', // request.remote_ip
          Time.now.to_default_s ]
      end
    end
  end
end

you can add that to an initializer and that should do the trick.

mr_sudaca
  • 1,156
  • 7
  • 9