My log files generate a LOT of output, and it's difficult to tell where the current action I'm looking at started logging. I though it would be as simple as deleting what was currently in the log file immediately before making the action (or at least adding some spacers), but editing the log files seems to make the application stop logging completely!
I can reset the application to start it logging again, but that brings me right back to square one - digging through a whole bunch of unneeded logs without knowing where the bits I actually wanted start.
Is there a way to edit the log file without killing Rail's ability to log?
Instead of deleting the file, do
cat /dev/null > log/production.log # or whatever the path to your file is
The problem is that when you delete the file, Rails still has the file open, so it is continuing to write to this now "deleted" file. By catting /dev/null to the file, you will clear out all of its contents without changing where the file handle is writing to.
My best guess as to why this is happening is that the I/O stream is being interrupted and corrupted (because you're modifying the file) while it's open (your application is running). You either need to restart your app or use Rob's solution.
However, an alternative solution is to use tail to view only the last 10 lines, you can specify more lines with tail -n 30, or whatever amount you wish. An even better solution is to use tail -f, which will show the file's tail and then print out new data as it is written to the file; very useful for monitoring log files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With