Home » PHP Code »

0

Hi friends, most of the hosting servers are not giving the permisstion to see the error log files. So, i would like to explain how to create custom log files using php.

The following script is for create the custom error log file.

PHP Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
error_reporting(0);  // to create  a own error handling

// user defined function

function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
// timestamp for the error entry.
$dt = date('Y-m-d H:i:s (T)');

// errors types

$errortype = array (
E_ERROR => 'Error',
E_WARNING => 'Warning',
E_PARSE => 'Parsing Error',
E_NOTICE => 'Notice',
E_CORE_ERROR => 'Core Error',
E_CORE_WARNING => 'Core Warning',
E_COMPILE_ERROR => 'Compile Error',
E_COMPILE_WARNING => 'Compile Warning',
E_USER_ERROR => 'User Error',
E_USER_WARNING => 'User Warning',
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Runtime Notice'
);

$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

$err = "<errorentry>\n";
$err .= "\t<datetime>" .$dt. "</datetime>\n";
$err .= "\t<errornum>" .$errno. "</errornum>\n";
$err .= "\t<errortype>" .$errortype[$errno]. "</errortype>\n";
$err .= "\t<errormsg>" .$errmsg. "</errormsg>\n";
$err .= "\t<scriptname>" .$filename. "</scriptname>\n";
$err .= "\t<scriptlinenum>" .$linenum. "</scriptlinenum>\n";

if (in_array($errno, $user_errors)) {
$err .= "\t<vartrace>" .wddx_serialize_value($vars, 'Variables'). "</vartrace>\n";
}
$err .= "</errorentry>\n\n";

// write the errors to one file that is

error_log($err, 3, 'error_log.log');

}

// to call the user defined function

$old_error_handler = set_error_handler('userErrorHandler');

?>

At the top of each page write the above code or write the above code at another file and include the that file at top of each page.

Hope that it is useful.


Related Posts

    How to get the php data grid?Facebook type notifications Using PHP and  JqueryHow to get the real IP address using php?How to add image in joomla for each article sidebar

 

Leave a Reply