Monitoring Rails’ log output while using Mongrel

If you install the Mongrel web server for Ruby, Rails is smart enough to start using it by default when you invoke script/server. However neither script/server nor mongrel_rails start (the recommended way to invoke Mongrel for a Rails project) will tail the rails logfile at log/development.log and give you the debug output you are accustomed to.

Solution: this small shell script, which simply invokes mongrel and immediately starts tailing the logfile, and upon receiving a Ctrl-C signal, stops tailing and shuts down the server. This is probably the behavior you were expecting, and presumably will be added by the Mongrel folks sooner or later.

#! /bin/bash

trap "{ mongrel_rails stop; exit 0; }" SIGINT

mongrel_rails start -d
tail -f log/development.log

I keep it in script/mongrel and then it acts as a no-fuss replacement for script/server.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*