2016-12-10 20:59:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard log levels
|
|
|
|
*
|
|
|
|
* @class WC_Log_Levels
|
2016-12-18 20:27:47 +00:00
|
|
|
* @version 1.0.0
|
2016-12-10 20:59:41 +00:00
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
abstract class WC_Log_Levels {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log Levels
|
|
|
|
*
|
2016-12-10 21:31:32 +00:00
|
|
|
* Description of levels:
|
|
|
|
* 'emergency': System is unusable.
|
|
|
|
* 'alert': Action must be taken immediately.
|
|
|
|
* 'critical': Critical conditions.
|
|
|
|
* 'error': Error conditions.
|
|
|
|
* 'warning': Warning conditions.
|
|
|
|
* 'notice': Normal but significant condition.
|
2017-05-18 08:32:13 +00:00
|
|
|
* 'info': Informational messages.
|
2016-12-10 21:31:32 +00:00
|
|
|
* 'debug': Debug-level messages.
|
|
|
|
*
|
2016-12-10 20:59:41 +00:00
|
|
|
* @see @link {https://tools.ietf.org/html/rfc5424}
|
|
|
|
*/
|
|
|
|
const EMERGENCY = 'emergency';
|
2016-12-11 12:01:12 +00:00
|
|
|
const ALERT = 'alert';
|
|
|
|
const CRITICAL = 'critical';
|
|
|
|
const ERROR = 'error';
|
|
|
|
const WARNING = 'warning';
|
|
|
|
const NOTICE = 'notice';
|
|
|
|
const INFO = 'info';
|
|
|
|
const DEBUG = 'debug';
|
2016-12-10 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Level strings mapped to integer severity.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-12-11 17:59:12 +00:00
|
|
|
protected static $level_to_severity = array(
|
2016-12-10 20:59:41 +00:00
|
|
|
self::EMERGENCY => 800,
|
2016-12-11 12:01:12 +00:00
|
|
|
self::ALERT => 700,
|
|
|
|
self::CRITICAL => 600,
|
|
|
|
self::ERROR => 500,
|
|
|
|
self::WARNING => 400,
|
|
|
|
self::NOTICE => 300,
|
|
|
|
self::INFO => 200,
|
|
|
|
self::DEBUG => 100,
|
2016-12-10 20:59:41 +00:00
|
|
|
);
|
|
|
|
|
2016-12-11 17:59:12 +00:00
|
|
|
/**
|
|
|
|
* Severity integers mapped to level strings.
|
|
|
|
*
|
|
|
|
* This is the inverse of $level_severity.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $severity_to_level = array(
|
|
|
|
800 => self::EMERGENCY,
|
|
|
|
700 => self::ALERT,
|
|
|
|
600 => self::CRITICAL,
|
|
|
|
500 => self::ERROR,
|
|
|
|
400 => self::WARNING,
|
|
|
|
300 => self::NOTICE,
|
|
|
|
200 => self::INFO,
|
|
|
|
100 => self::DEBUG,
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-12-10 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* Validate a level string.
|
|
|
|
*
|
|
|
|
* @param string $level
|
|
|
|
* @return bool True if $level is a valid level.
|
|
|
|
*/
|
|
|
|
public static function is_valid_level( $level ) {
|
2016-12-22 21:29:47 +00:00
|
|
|
return array_key_exists( strtolower( $level ), self::$level_to_severity );
|
2016-12-10 20:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate level string to integer.
|
|
|
|
*
|
|
|
|
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
|
|
|
|
* @return int 100 (debug) - 800 (emergency) or 0 if not recognized
|
|
|
|
*/
|
|
|
|
public static function get_level_severity( $level ) {
|
|
|
|
if ( self::is_valid_level( $level ) ) {
|
2016-12-22 21:29:47 +00:00
|
|
|
$severity = self::$level_to_severity[ strtolower( $level ) ];
|
2016-12-10 20:59:41 +00:00
|
|
|
} else {
|
|
|
|
$severity = 0;
|
|
|
|
}
|
|
|
|
return $severity;
|
|
|
|
}
|
|
|
|
|
2016-12-11 17:59:12 +00:00
|
|
|
/**
|
|
|
|
* Translate severity integer to level string.
|
|
|
|
*
|
|
|
|
* @param int $severity
|
|
|
|
* @return bool|string False if not recognized. Otherwise string representation of level.
|
|
|
|
*/
|
|
|
|
public static function get_severity_level( $severity ) {
|
|
|
|
if ( array_key_exists( $severity, self::$severity_to_level ) ) {
|
|
|
|
return self::$severity_to_level[ $severity ];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 20:59:41 +00:00
|
|
|
}
|