1

I have poorly written PHP application that produces a lot of E_NOTICE and E_WARNING messages to error log. I can't do much about it, but it's hard to keep track of those real errors like E_ERROR and worse.

The question is: Can I have multiple error log files with different LogLevels for single virtual host in Apache?

For example one with LogLevel notice and one with LogLevel error.

  • I hope you were able to get your issue resolved. If my answer was helpful to you, I'd appreciate if you could mark it as accepted so I can get credit for it. Thanks – sa289 Jul 13 '15 at 20:51
0

I don't know off hand if there's a native way to do it (but see bottom of this response), but if you're on Linux, you could run a few commands on the master log like tail -f /path/to/main/ | grep errorstring > error.log tail -f /path/to/main/ | grep warningstring > warning.log

The -f flag will keep watching for new entries. Replace errorstring or warningstring with whatever the exact text is that gets logged for all entries of type error or of type warning.

You can run these in the background and so they don't terminate when your shell session closes by putting each command into a bash script and then running it using the following syntax nohup /path/to/script.sh >/dev/null 2>&1 &

If it's just for temporary use you could start them manually in a couple of screen sessions. For long term use, be sure to put some log rotation in place so they don't grow too large.

Another more-native approach would be to set a custom PHP error handler function to do the logging. You could apply it to all PHP code without modifying the app by using the auto_prepend_file ini directive.

  • Thank you for both solutions. I was trying to avoid adding new scripts because of log rotation, however I didn't know about auto_prepend_file directive so I'll give it a shoot. – ioku Apr 3 '15 at 10:21
0

Cool another way to do this is to configure the rsyslog daemon to create these files. Basically you can setup a rule to output to file based on a text match. Open up /etc/rsyslog.conf and paste this in there

if $programname == 'my-name' and $msg contains 'errorstring' then /var/log/my-error.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.