0

I want an error log file attached to my application I have developed. My application is made in php mysql and I need that whatever error is found it should be displayed in a .txt file with full explanation like what is the error in which line number like that. I have no Idea how can I get that.

Can anyone help me creating this and changes do I have to make to get those error in my application. My server is an IIS server.

Rakhi
  • 369
  • 2
  • 6
  • 19
  • Use `try` `catch` and in catch log the error to the file where you want to write the error. – 웃웃웃웃웃 Aug 17 '13 at 05:57
  • 1
    There are already log files being created by PHP/IIS that you should be able to look at. Are these not sufficient? Are you looking for a more custom logging facility? What have you looked at so far? – deceze Aug 17 '13 at 05:58
  • the error file inside Apache shows error off all other application projects error but I want particularly for this application how can I do that??? – Rakhi Aug 17 '13 at 06:11

1 Answers1

3

First we have to see types of errors in PHP:

Notices: These are non-critical errors which PHP encounters while running a script. For example, a variable accessibility before it is declared.

Warnings: The are more serious errors. For example, using include()without the existence of the file.

Fatal Errors: These errors are critical errors. For example, creating an object of a non-existent class. These errors terminate the script’s execution immediately. These are intimated to the users.

Now, the process of Catching these 3 types of errors

//Setting for the PHP Error Handler
set_error_handler( call_back function or class );

//Setting for the PHP Exceptions Error Handler
set_exception_handler(call_back function or class);

//Setting for the PHP Fatal Error
register_shutdown_function(call_back function or class);

Whatever the function or class is described by user for tracing the error the following command is used:

 $debug = debug_backtrace();

 print_r($debug);

If you print the debug then it will show you the running process and file name, line number of the error.

Vineet1982
  • 7,730
  • 4
  • 32
  • 67