Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dauber

macrumors regular
Original poster
Jan 10, 2012
155
20
Chicago
So....I'm running some local web sites on both my 2007 MacBook running Lion and my mid-2011 iMac running Yosemite...local to test on before I push them online, of course...using the vhosts functionality of Apache.

Each site has its own error log, and each error log fires exactly when it should and where it should.

However: there are no line breaks or carriage returns. Whenever I send something to the error log, any line breaks are replaced with the characters "\n" and the text just runs on.

Is there any way around that??
 
Last edited:

markoxford

macrumors newbie
Apr 15, 2015
2
0
Yes — if you change the PHP config

By default when PHP tries to log errors is does so using syslog (which then passes it on to Apache). Because line breaks are used to delineate each log line any new lines in the error message are escaped — hence the "\n" you see in the log.

The simplest (best?) way is to log php errors to a separate file. That way apache error logs will only contain web server errors (file not found, permission errors etc) and php errors will go to the file you specify.

If you want one for each vhost set the file location in the apache config file: e.g.
Code:
php_value error_log "/var/log/apache2/php-errors-for-vhost1.log

You will need that file to either be in a directory that PHP can write to or create it yourself and set permissions for PHP to write to it, e.g. using the terminal
Code:
sudo touch /var/log/apache2/php-errors-for-vhost1.log
sudo chown www /var/log/apache2/php-errors-for-vhost1.log

NOTE: With a default php config you will get an error about timezones*, to correct this just add your timezone info: e.g.
Code:
php_value date.timezone "Europe/London"
For a full list of timezones see http://php.net/manual/en/timezones.php

* this is because it is now PHP's job to put the timestamp in the log file whereas originally that was handled by Apache.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.