Created
December 7, 2012 18:09
-
-
Save pmontrasio/4235159 to your computer and use it in GitHub Desktop.
Gets the last POST parameters in Rails's log/development.log and pretty prints them
This file contains 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
#!/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 |
It wasn't working for me with Rails 3.2.x
#!/bin/bash
echo $(grep -e "Started \(GET\|POST\|PUT\)" log/development.log | tail -1)
grep -e "Parameters:" log/development.log | tail -1 | sed "s|Parameters:\s||" | ruby -ne 'require "pp"; pp eval($_)'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A naive shell script to monitor the development log:
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.