0

I need to log Fatal-errors of my website.

I normally check error.log and debug.log files for CakePHP errors.
But I found out that PHP related fatal errors aren't logged someplace.
It is also discussed in this thread.

I checked php.ini. IT has following lines:

log_errors = On
;error_log = filename

I don't have rights to change php.ini. I can ask admin to change this, but it seems like I need to ask him every time I need a change :) I also have concerns about performance. Whether logging errors can decrease performance or not?

So I find out that I can put following two lines inside my script to log errors and change folder or file name when I need.

ini_set("log_errors", 1);
ini_set("error_log", "/path/to/php-error.log");

So I want to know where to put this lines inside my codes? Should I put it inside AppController::beforeFilter ? Or is there a better place/solution in CakePHP 2 configuration?

3
  • 1
    As far as I'm aware you can't log fatal errors inside PHP since a fatal error is, well, fatal to the PHP interpreter. Your ini_set method is also potentially flawed since it won't catch any errors up to an including loading the file those lines are inside, so early death still won't be logged appropriately. Commented Aug 30, 2012 at 8:29
  • isn't apache logging those errors too? Commented Aug 30, 2012 at 8:43
  • If the fatal error happens in any included file (i.e. not the first request file) it should be fairly easy to log using [set_error_handler()](http://php.net/manual/en/function.set-error-handler.php). Parse/Compile errors on the other hand cannot be handled. Commented Aug 30, 2012 at 9:30

3 Answers 3

2

this is an old thread. in the meantime with cake 2.x errors are all logged in productive mode - so also fatal errors.

trigger one and check out your /tmp/logs/error.log

but you can easily find that out looking at the core code: https://github.com/cakephp/cakephp/blob/master/lib/Cake/Error/ErrorHandler.php#L189

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

2 Comments

unfortunately fatal errors aren't logged in error.log. I checked many times that file after seeing fatal errors on browser window.
are you on the latest 2.x? for it it works anyway - oh, it might be >= 2.2: book.cakephp.org/2.0/en/appendices/… - if you cant upgrade you need to use my "register_shutdown_function" function you linked in your question.
1

There is framework defined configuration settings. You can use the Error Handling configuration class.

Here is changing fatal error behavior link, that will help you to achieve the same.

Comments

0

register_shutdown_function();

http://php.net/manual/en/function.register-shutdown-function.php

Comments

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.