Created
September 15, 2025 12:08
-
-
Save mucaho/1cc533a2133ad06ec463de51432fd7e5 to your computer and use it in GitHub Desktop.
Log HTTP requests in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # replace ruby version and possibly path in the commands below | |
| sed_line=$(grep -n "def delete" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][DELETE]: #{self.class.name}.#{__method__} called for path: #{path},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb | |
| sed_line=$(grep -n "def put" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][PUT]: #{self.class.name}.#{__method__} called for path: #{path},\\n data: #{data},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb | |
| sed_line=$(grep -n "def patch" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][PATCH]: #{self.class.name}.#{__method__} called for path: #{path},\\n data: #{data},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb | |
| sed_line=$(grep -n "def post" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][POST]: #{self.class.name}.#{__method__} called for path: #{path},\\n data: #{data},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb | |
| sed_line=$(grep -n "def head" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][HEAD]: #{self.class.name}.#{__method__} called for path: #{path},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb | |
| sed_line=$(grep -n "def get" /opt/ruby/lib/ruby/3.2.0/net/http.rb | cut -d : -f 1) | |
| sed -i "$sed_line"' a Rails.logger.warn("[HTTP][GET]: #{self.class.name}.#{__method__} called for path: #{path},\\n backtrace: #{Rails.backtrace_cleaner.clean(caller).join("|")}")' /opt/ruby/lib/ruby/3.2.0/net/http.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment