Why does my Apache2::Log output replace newlines with \n?
Asked Answered
C

3

2

I've set up multiple vhosts under apache2 / mod_perl. I used the ErrorLog directive to get a separate error log for each vhost. This only worked as expected when I used Apache2::Log. 'warn' would only log to the regular error log.

So that's all working. Finally. But there's one issue remaining: When I log via $r->log_error, I find that newlines are replaced with \n

Any idea why this happens, and how it can be fixed?

Thanks.

Cystocarp answered 15/10, 2009 at 17:32 Comment(1)
Are you sure you're not putting them in single quotes? 'Hi\n' vs "Hi\n"Discrete
S
8

This is not a mod_perl problem, but an Apache one. Apparently there are some security concerns with printing unescaped output to the error logs (I'm not entirely sure why) so you have to explicitly enable this in Apache when building/configuring it using this:

CFLAGS=-DAP_UNSAFE_ERROR_LOG_UNESCAPED ./configure

If you're using an already installed apache, there's not much you can do to change this.

Skilled answered 15/10, 2009 at 19:33 Comment(0)
M
0

If you have a pre-built install, you can use this line of code to fix the issue but it must be included in every page execution within your vhost, say in a header.php or config.php file.

ini_set('error_log','/var/log/apache2/error.log');
Maladapted answered 19/1, 2012 at 16:6 Comment(1)
That's not really very clever, for an error log. If this is left out in error...Crellen
M
0

i know this is very old thread, but still coming on top on google results, so just to help all, the following changes in mod_perl.pl did helped me:

comment out below:

BEGIN { *CORE::GLOBAL::warn = \&Apache2::ServerRec::warn; }

the above is for: Make warnings go to the virtual host's log and not the main server log.

i hope this helps anyone out there like me :)

Malvoisie answered 22/2, 2013 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.