4

This is what I tell php to do:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '0');
ini_set('log_errors', 1);
ini_set('error_log', 'errors.log');
ini_set('error_append_string', 'APP');
ini_set('error_prepend_string', 'PRE');
?>

Hoping that I would get all errors reported in one file, with "PRE" before the message and "APP" after the message. (My goal is to make PRE and APP into /n /r or something...)

But my error reporting log looks like this:

[14-May-2013 00:16:26] PHP Notice: Undefined variable: nonexistentvariable in /home/www/dir/index.php on line 14[14-May-2013 00:16:28] PHP Notice: Undefined variable: nonexistentvariable in /home/www/dir/index.php on line 14

No PRE, no APP...

How do I get it in there, so that my error reporting file will have each error on a newline, rather than a loooong string of errors that's not helpful to me?

EDIT: So I noticed that with ini_set('display_errors', '1'); the "APP" and "PRE" strings are displayed on the page, in the error message.

That means I really need to find out where I can change the format for how php logs the errors. For example this whole timestamp thing - where is that specified?

EDIT: It is not possible to change the way php logs errors, you have to make your own error handler.

ANSWER: To truly achieve what I was going to, I asked a different question (to be more precise). How to change the way PHP writes errors in the error log file?

2 Answers 2

5

As the documentation says nothing to that, I have tested your example. I realized that error_append/prepend_string only works for displayed but not logged errors

My goal is to make PRE and APP into /n /r or something...

You should use a regex for that. Should be possible, as every log messages starts with nearly same prefix. Will prepare one....

Sign up to request clarification or add additional context in comments.

12 Comments

as for your realization: Yes, I had the same results. The log message is not effected by append_string.
Are you suggesting to rewrite the error log file and add newlines after each page load or something like that?
and do what with the expression?
I have currently something unfinished like this: '/^\[.*?\] PHP (Notice|Parse error):/m' .. Of course the list Notice|Parse error must be extended. But it looks like finding the right regex can be tricky here (but it is possible)... maybe google finds something as well
I expect that there are tools for that (don't actually having one in mind). But check this for example, maybe it enlights you :) : serverfault.com/questions/53894/colorize-monitoring-of-logs
|
-1

check phpinfo(); after ini_sets

2 Comments

it updated php info correctly... I assume the problem is with "display_erors" vs. "log_errors" - meaning it seems to me as if log_errors doesn't utilize the ap/pre-pend_string
Just a complete non-answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.