views:

51

answers:

1

My Perl/FastCGI app makes extensive use of "print STDERR" to log all sorts of debugging info to the Apache error log file.

I insert frequent line breaks myself, but Apache (or perhaps FastCGI?) still feels the need to insert extra line breaks, usually right in the middle of my nicely formatted output.

How can I stop this from happening?

Here is an example:

[Sun Sep 19 12:51:49 2010] [warn] mod_fcgid: stderr: request OK: client / index :0.035902 wallclock secs ( 0.030 usr  0.000 sys +  0.000 cusr  0.000 csys =  0.030 CPU)
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: REQUEST pid:3569   ctr:4   time: 15   path:/client/index
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: REQUEST: /client/index   log: 9473
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 1--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 2--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 3--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 4--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 5--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 6--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 7--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 8--45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 9--4
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 5678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 10-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 11-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 12-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 13-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 14-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 15-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 16-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 17-45678901234567890123456789012345678901234567890
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 18-4567890123456789012345678901234567890123456789
[Sun Sep 19 12:51:52 2010] [warn] mod_fcgid: stderr: 0

Each line should contain 51 characters, including a \n, and not counting apache's preamble. Each line is output in it's own print() call, so it's not a consequence of dumping a lot of text at once.

It seems to happen every 504 characters, starting from the beginning of each FastCGI request. If I have a bunch of requests in a row that print very little info, I never see the line break.

+1  A: 

Why don't use just use Log4Perl instead?

Can you give some examples of the unwanted line breaks? Are you sure the error log really has extra line breaks or is something else, such as your terminal, wrapping them?

This sounds suspiciously like buffered output. What happens if you unbuffer STDERR?

 {
 my $old = select(STDERR);
 $|++;
 select( $old );
 }
brian d foy
Log4Perl looks good, it's just what I need. But I'm working with a large code base that uses print STDERR and I can't change it all right now. I've added an example and more info above. Thanks for the tip.
NXT
PS it's not being wrapped by the terminal
NXT
Good suggestion with $|, but I tried it and it made no difference at all. I also tried $|=1 at the beginning of each request. I think the buffering is in FastCGI but I can't find documentation of it.
NXT