Link to home
Create AccountLog in
Avatar of pnoeric
pnoericFlag for United States of America

asked on

Inserting newline into Apache error log

Ok, here's an easy one -- I'm using php's error_log() function to send error messages to the Apache log. (I'm on Windows, PHP 5.2.5 and Apache 2.2.8.) I'd like to insert a line break in my error messages. \r and \n both don't do the job (they show up exactly as "\r" and "\n" in the log... doh!).

Any trick to this? Is it like an Apache or PHP config option I'm overlooking or something?

sample of what I'm getting (note "\n"):

[Fri Mar 07 13:29:41 2008] [error] [client] poll calc:\nfield 13 (Four), 4 out of 19 is 21% (stuffed in field 4), referer: http://localhost/page.php
Avatar of hielo
Flag of Wallis and Futuna image

Enclose the error message in double quotes, not apostrophes:
Good: error_log("Hello \nWorld",...
Bad:  error_log('Hello \nWorld',...;
Avatar of pnoeric


Yeah, I'm doing that. No dice.
You can't put a line break in the error log... a new line in the error log represents a new error
From what I read on the comments section of the manual, you can't do multi-line log entries. The "workaround" that is suggested is:

$errlines = explode("\n",$errmsg);
foreach ($errlines as $txt) { error_log($txt); }
Avatar of ravenpl
Flag of Poland image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
If you set a custom error log for PHP, THAT error log will handle newlines.  See the error_log configuration item: