Re: Newlines in error_log

Juha-Jarmo Heinonen <[email protected]> Fri, 25 Jun 2004 16:45:40 +0300
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
On 25.6.2004, at 02:16, Dave wrote:

> I've got a little problem with the error reporting of mod-ruby. It was 
> working correctly before, but I upgraded to apache and mod-ruby, and 
> now my error messages are all appearing on one line like so:
>

> Any ideas how I can get the escape characters to be interpreted again? 
> As you can imagine, it makes debugging kind of hard.
>
> - Dave
>
>

I had the same problem and made a shell script to make debugging output 
nicer:

----------------------------
#!/bin/bash
tail -n 1000 -F /var/log/apache2/error.log | grep --line-buffered 
mod_ruby | sed -u "s/error in ruby\\\\n/\\n-=-=-=-=-=-\\n/g" | sed -u 
"s/\\\\n/\\n/g" | sed -u "s/\\\\t/\\t/g"

----------------------------

The "--line-buffered" part in grep is needed, because you need to feed 
the pipes thru the sed expressions one line at a time.


Another way to do it would be this (in ruby):

$stderr.reopen("~/my_tracefile.txt","a")

You may also want to put some of your own comments to the log to trace 
what's happening in your code without messing up html:

$stderr.write("Entering stage 2, let's see if we encounter errors..\n")

You can also make a combination of the two, like this:

# early in the code
$my_debuglog = open("/var/log/my_logfile","a")

# later in the code you can append comments to it like this:
$my_debuglog.write("Query results:\n#{results.inspect}\n--------\n")


Inspecting realtime output of those is easiest with tail:
tail -f /var/log/my_logfile