Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: write php errors to file  (Read 538 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
write php errors to file
« on: February 03, 2012, 04:22:46 pm »

maybe someone find it useful  :)

in snews after session_start() add

Code: [Select]
<?php
define
("LOG_FILE""errors.log");
function 
my_error_handler($errno$errstr$errfile$errline ){
$time date("g:i a, j F Y");
$adr 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ;
switch (
$errno) {
    case 
E_USER_ERROR:
      
error_log("[E_USER_ERROR # $errno]: $errstr \n Fatal error on line $errline in file $errfile - $time - \n\n"'3'LOG_FILE);
      break;    
case E_USER_WARNING:
      
error_log("[E_USER_WARNING # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;    
case E_USER_NOTICE:
      
error_log("[E_USER_NOTICE # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;  
case E_NOTICE:
      
error_log("$adr \n[E_NOTICE # $errno]:  $errstr \nin $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;
case E_PARSE:
      
error_log("[E_PARSE # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;  
case E_WARNING:
      
error_log("[E_WARNING # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;
case E_CORE_ERROR:
      
error_log("[E_CORE_ERROR # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;
case E_CORE_WARNING:
      
error_log("[E_CORE_WARNING # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;

case E_COMPILE_ERROR:
      
error_log("[E_COMPILE_ERROR # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;

case E_COMPILE_WARNING:
      
error_log("[E_COMPILE_WARNING # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;

case E_ALL:
      
error_log("[E_ALL # $errno]: $errstr \n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;

default:
      
error_log("Unknown error [#$errno]: $errstr n in $errfile on line $errline - $time - \n\n"'3'LOG_FILE);
      break;
  }  
// Don't execute PHP's internal error handler set to TRUE
  
return TRUE;
}
// Use set_error_handler() to tell PHP to use our method
$old_error_handler set_error_handler("my_error_handler");
?>

I find original from here
http://www.stanford.edu/dept/its/communications/webservices/wiki/index.php/How_to_perform_error_handling_in_PHP
and make it to fit to my needs  ;D
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: write php errors to file
« Reply #1 on: February 09, 2012, 02:15:54 pm »

Hi Sibas,
Nice script, thank you for sharing.

+karma for you

awesome day

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: write php errors to file
« Reply #2 on: February 09, 2012, 02:19:19 pm »

where is the karma button gone  ??? :P :o

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: write php errors to file
« Reply #3 on: February 09, 2012, 02:28:55 pm »

ha ha ha  ;D
karma to u!!!!
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: write php errors to file
« Reply #4 on: February 09, 2012, 02:35:05 pm »

how do you do that ?  :P

Please, can some one show me where is the karma +- button  ??? ??? ???  ;D
« Last Edit: February 09, 2012, 03:27:06 pm by mosh »
Logged