Posted By

sadus on 11/16/10


Tagged

php error log color tail syslog


Versions (?)

PHP error_log to syslog to a custom file pipe to tail your errors.


 / Published in: PHP
 

So i wanted to spit all my errorlog(); and errorreporting(E_ALL); to syslog on my MacOSX and syslog would output it on a custom file.

  1. use this line so all your errors are logged.
  2. <?php
  3. ?>
  4.  
  5. go to your php.ini and set the following:
  6. error_log = syslog
  7.  
  8. go to your apache.conf (httpd.conf) and set the following:
  9. ErrorLog syslog:local3
  10.  
  11. go to your syslog.conf and set the following at the very end of the file:
  12. local3.* /var/log/httpd-php.log
  13.  
  14. then look for a line like this:
  15. *.notice;authpriv,remoteauth,ftp,install,internal.none /var/log/system.log
  16.  
  17. and add local3.none
  18. *.notice;authpriv,remoteauth,ftp,install,internal.none /var/log/system.log
  19.  
  20. this will make sure httpd php errors won't log to your /var/log/system.log file that's reserved for your machine logs.
  21.  
  22. and you are set
  23.  
  24. when you want to log something, use error_log(); example:
  25. error_log("Error: " .$user. " is not authenticated");
  26.  
  27. and then to view your errors in real time:
  28. tail -F /var/log/httpd-php.log
  29.  
  30. you can also color this using "colorize" on OSX/FreeBSD or "ccze" on Linux.
  31.  
  32. enjoy!

Report this snippet  

You need to login to post a comment.