public
Last active

Gets the last POST parameters in Rails's log/development.log and pretty prints them

  • Download Gist
post_params
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash
# DO NOT USE ON PRODUCTION LOGS: maybe there are ways to inject Ruby code into the
# parameters hash and you'll end up evaluating it
#
# usage: post_params
# run this in the main Rails directory
# tested on Linux with ruby 1.9.3-p327, bash 4.2.24
 
last_post_line=`grep -n "Started POST " log/development.log |tail -1|cut -f1 -d":"`
hash_line=`expr $last_post_line + 2`
hash=`sed -n -e "${hash_line}p" log/development.log |sed -e 's/Parameters:/hash =/'`
 
echo "require 'pp';$hash;pp hash" | ruby -E UTF-8

A naive shell script to monitor the development log:

while true; do
  inotifywait -q log/development.log
  post_params
done

This is suboptimal because Rails modifies the log file many times during the processing of a request. The monitoring program should be smart enough to run post_params only when the file has been left alone for a few seconds.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.