mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
Logging. Use constants instead of numeric values in the switch, bump
notices, warnings, and ignored messages to level 6 instead of ignoring them completely.
This commit is contained in:
parent
dc495ea8ea
commit
93f4a26ab0
1 changed files with 67 additions and 62 deletions
113
lib/log.lib.php
113
lib/log.lib.php
|
@ -20,23 +20,25 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@function log_event
|
* log_event
|
||||||
@discussion logs an event either to a database
|
* Logs an event to a defined log file based on config options
|
||||||
or to a defined log file based on config options
|
*/
|
||||||
*/
|
function log_event($username, $event_name, $event_description, $log_name) {
|
||||||
function log_event($username='Unknown',$event_name,$event_description,$log_name='ampache') {
|
|
||||||
/* Set it up here to make sure it's _always_ the same */
|
/* Set it up here to make sure it's _always_ the same */
|
||||||
$log_time = time();
|
$time = time();
|
||||||
|
// Turn time into strings
|
||||||
|
$log_day = date('Ymd', $time);
|
||||||
|
$log_time = date('Y-m-d H:i:s', $time);
|
||||||
|
|
||||||
/* must have some name */
|
/* must have some name */
|
||||||
if (!strlen($log_name)) { $log_name = 'ampache'; }
|
$log_name = $log_name ? $log_name : 'ampache';
|
||||||
|
|
||||||
$username = $username ? $username : 'ampache';
|
$username = $username ? $username : 'ampache';
|
||||||
|
|
||||||
$log_filename = Config::get('log_path') . "/$log_name." . date("Ymd",$log_time) . ".log";
|
$log_filename = Config::get('log_path') . "/$log_name.$log_day.log";
|
||||||
$log_line = date("Y-m-d H:i:s",$log_time) . " [$username] ($event_name) -> $event_description \n";
|
$log_line = "$log_time [$username] ($event_name) -> $event_description \n";
|
||||||
|
|
||||||
|
// Do the deed
|
||||||
$log_write = error_log($log_line, 3, $log_filename);
|
$log_write = error_log($log_line, 3, $log_filename);
|
||||||
|
|
||||||
if (!$log_write) {
|
if (!$log_write) {
|
||||||
|
@ -45,10 +47,10 @@ function log_event($username='Unknown',$event_name,$event_description,$log_name=
|
||||||
|
|
||||||
} // log_event
|
} // log_event
|
||||||
|
|
||||||
/*!
|
/*
|
||||||
@function ampache_error_handler
|
* ampache_error_handler
|
||||||
@discussion an error handler for ampache that traps
|
* An error handler for ampache that traps as many errors as it can and logs
|
||||||
as many errors as it can and logs em
|
* them.
|
||||||
*/
|
*/
|
||||||
function ampache_error_handler($errno, $errstr, $errfile, $errline) {
|
function ampache_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
|
|
||||||
|
@ -56,25 +58,29 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
$level = 1;
|
$level = 1;
|
||||||
|
|
||||||
switch ($errno) {
|
switch ($errno) {
|
||||||
case '2':
|
case E_WARNING:
|
||||||
$error_name = "Runtime Error";
|
$error_name = 'Runtime Error';
|
||||||
break;
|
break;
|
||||||
case '128':
|
case E_COMPILE_WARNING:
|
||||||
case '8':
|
case E_NOTICE:
|
||||||
case '32':
|
case E_CORE_WARNING:
|
||||||
return true;
|
$error_name = 'Warning';
|
||||||
|
$level = 6;
|
||||||
break;
|
break;
|
||||||
case '1':
|
case E_ERROR:
|
||||||
$error_name = "Fatal run-time Error";
|
$error_name = 'Fatal run-time Error';
|
||||||
break;
|
break;
|
||||||
case '4':
|
case E_PARSE:
|
||||||
$error_name = "Parse Error";
|
$error_name = 'Parse Error';
|
||||||
break;
|
break;
|
||||||
case '16':
|
case E_CORE_ERROR:
|
||||||
$error_name = "Fatal Core Error";
|
$error_name = 'Fatal Core Error';
|
||||||
break;
|
break;
|
||||||
case '64':
|
case E_COMPILE_ERROR:
|
||||||
$error_name = "Zend run-time Error";
|
$error_name = 'Zend run-time Error';
|
||||||
|
break;
|
||||||
|
case E_STRICT:
|
||||||
|
$error_name = "Strict Error";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$error_name = "Error";
|
$error_name = "Error";
|
||||||
|
@ -82,34 +88,33 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
break;
|
break;
|
||||||
} // end switch
|
} // end switch
|
||||||
|
|
||||||
|
// List of things that should only be displayed if they told us to turn
|
||||||
|
// on the firehose
|
||||||
|
$ignores = array(
|
||||||
|
// We know var is deprecated, shut up
|
||||||
|
'var: Deprecated. Please use the public/private/protected modifiers',
|
||||||
|
// getid3 spews errors, yay!
|
||||||
|
'getimagesize() [',
|
||||||
|
'Non-static method getid3',
|
||||||
|
'Assigning the return value of new by reference is deprecated',
|
||||||
|
// The XML-RPC lib is broken (kinda)
|
||||||
|
'used as offset, casting to integer'
|
||||||
|
);
|
||||||
|
|
||||||
/* Don't log var: Deprecated we know shutup!
|
foreach($ignores as $ignore) {
|
||||||
* Yea now getid3() spews errors I love it :(
|
if (strpos($errstr, $ignore) !== false) {
|
||||||
*/
|
$error_name = 'Ignored ' . $error_name;
|
||||||
if (strstr($errstr,"var: Deprecated. Please use the public/private/protected modifiers") OR
|
$level = 6;
|
||||||
strstr($errstr,"getimagesize() [") OR strstr($errstr,"Non-static method getid3") OR
|
}
|
||||||
strstr($errstr,"Assigning the return value of new by reference is deprecated")) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr($errstr,"date.timezone")) {
|
if (strpos($errstr,"date.timezone") !== false) {
|
||||||
$error_name = "Warning";
|
$error_name = 'Warning';
|
||||||
$errstr = "You have not set a valid timezone (date.timezone) in your php.ini file. This may cause display issues with dates. This warning is non-critical and not caused by Ampache.";
|
$errstr = 'You have not set a valid timezone (date.timezone) in your php.ini file. This may cause display issues with dates. This warning is non-critical and not caused by Ampache.';
|
||||||
}
|
|
||||||
|
|
||||||
/* The XML-RPC lib is broken, well kind of
|
|
||||||
* shut your pie hole
|
|
||||||
*/
|
|
||||||
if (strstr($errstr,"used as offset, casting to integer")) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$log_line = "[$error_name] $errstr in file $errfile($errline)";
|
$log_line = "[$error_name] $errstr in file $errfile($errline)";
|
||||||
debug_event('PHP Error',$log_line,$level);
|
debug_event('PHP', $log_line, $level, '', 'ampache');
|
||||||
|
|
||||||
// When a dir is defined lets log it to a logfile
|
|
||||||
if (Config::get('log_path') != "")
|
|
||||||
log_event("ampache","PHP Error", $log_line);
|
|
||||||
|
|
||||||
} // ampache_error_handler
|
} // ampache_error_handler
|
||||||
|
|
||||||
|
@ -119,17 +124,17 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
|
||||||
* log_event. It checks for conf('debug') and conf('debug_level') and only
|
* log_event. It checks for conf('debug') and conf('debug_level') and only
|
||||||
* calls log event if both requirements are met.
|
* calls log event if both requirements are met.
|
||||||
*/
|
*/
|
||||||
function debug_event($type,$message,$level,$file='',$username='') {
|
function debug_event($type, $message, $level, $file = '', $username = '') {
|
||||||
|
|
||||||
if (!Config::get('debug') || $level > Config::get('debug_level')) {
|
if (!Config::get('debug') || $level > Config::get('debug_level')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$username) {
|
if (!$username && isset($GLOBALS['user'])) {
|
||||||
$username = $GLOBALS['user']->username;
|
$username = $GLOBALS['user']->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_event($username,$type,$message,$file);
|
log_event($username, $type, $message, $file);
|
||||||
|
|
||||||
} // debug_event
|
} // debug_event
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue