extending debug function
This commit is contained in:
parent
d3fdd18810
commit
dcdc0ef297
1 changed files with 41 additions and 10 deletions
|
@ -143,23 +143,54 @@ class WP_FEATURED2RSS {
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param int $level
|
* @param int $level
|
||||||
|
*
|
||||||
|
* @output log to syslog | wp_die on high level
|
||||||
|
* @return false on not taking action, true on log sent
|
||||||
*/
|
*/
|
||||||
static function debug( $message, $level = LOG_NOTICE ) {
|
public static function debug( $message, $level = LOG_NOTICE ) {
|
||||||
|
if ( empty( $message ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
if ( @is_array( $message ) || @is_object ( $message ) )
|
if ( @is_array( $message ) || @is_object ( $message ) )
|
||||||
$message = json_encode($message);
|
$message = json_encode($message);
|
||||||
|
|
||||||
|
$levels = array (
|
||||||
|
LOG_EMERG => 0, // system is unusable
|
||||||
|
LOG_ALERT => 1, // Alert action must be taken immediately
|
||||||
|
LOG_CRIT => 2, // Critical critical conditions
|
||||||
|
LOG_ERR => 3, // Error error conditions
|
||||||
|
LOG_WARNING => 4, // Warning warning conditions
|
||||||
|
LOG_NOTICE => 5, // Notice normal but significant condition
|
||||||
|
LOG_INFO => 6, // Informational informational messages
|
||||||
|
LOG_DEBUG => 7, // Debug debug-level messages
|
||||||
|
);
|
||||||
|
|
||||||
switch ( $level ) {
|
// number for number based comparison
|
||||||
case LOG_ERR :
|
// should work with the defines only, this is just a make-it-sure step
|
||||||
wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' );
|
$level_ = $levels [ $level ];
|
||||||
exit;
|
|
||||||
default:
|
// in case WordPress debug log has a minimum level
|
||||||
if ( !defined( 'WP_DEBUG' ) || WP_DEBUG != true )
|
if ( defined ( 'WP_DEBUG_LEVEL' ) ) {
|
||||||
return;
|
$wp_level = $levels [ WP_DEBUG_LEVEL ];
|
||||||
break;
|
if ( $level_ < $wp_level ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log( __CLASS__ . " => " . $message );
|
// ERR, CRIT, ALERT and EMERG
|
||||||
|
if ( 3 >= $level_ ) {
|
||||||
|
wp_die( '<h1>Error:</h1>' . '<p>' . $message . '</p>' );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trace = debug_backtrace();
|
||||||
|
$caller = $trace[1];
|
||||||
|
$parent = $caller['function'];
|
||||||
|
|
||||||
|
if (isset($caller['class']))
|
||||||
|
$parent = $caller['class'] . '::' . $parent;
|
||||||
|
|
||||||
|
return error_log( "{$parent}: {$message}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue