WC_Log_Levels

Standard log levels.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-log-levels.php  
  1. abstract class WC_Log_Levels { 
  2.  
  3. /** 
  4. * Log Levels 
  5. * Description of levels: 
  6. * 'emergency': System is unusable. 
  7. * 'alert': Action must be taken immediately. 
  8. * 'critical': Critical conditions. 
  9. * 'error': Error conditions. 
  10. * 'warning': Warning conditions. 
  11. * 'notice': Normal but significant condition. 
  12. * 'informational': Informational messages. 
  13. * 'debug': Debug-level messages. 
  14. * @see @link {https://tools.ietf.org/html/rfc5424} 
  15. */ 
  16. const EMERGENCY = 'emergency'; 
  17. const ALERT = 'alert'; 
  18. const CRITICAL = 'critical'; 
  19. const ERROR = 'error'; 
  20. const WARNING = 'warning'; 
  21. const NOTICE = 'notice'; 
  22. const INFO = 'info'; 
  23. const DEBUG = 'debug'; 
  24.  
  25. /** 
  26. * Level strings mapped to integer severity. 
  27. * @var array 
  28. */ 
  29. protected static $level_to_severity = array( 
  30. self::EMERGENCY => 800,  
  31. self::ALERT => 700,  
  32. self::CRITICAL => 600,  
  33. self::ERROR => 500,  
  34. self::WARNING => 400,  
  35. self::NOTICE => 300,  
  36. self::INFO => 200,  
  37. self::DEBUG => 100,  
  38. ); 
  39.  
  40. /** 
  41. * Severity integers mapped to level strings. 
  42. * This is the inverse of $level_severity. 
  43. * @var array 
  44. */ 
  45. protected static $severity_to_level = array( 
  46. 800 => self::EMERGENCY,  
  47. 700 => self::ALERT,  
  48. 600 => self::CRITICAL,  
  49. 500 => self::ERROR,  
  50. 400 => self::WARNING,  
  51. 300 => self::NOTICE,  
  52. 200 => self::INFO,  
  53. 100 => self::DEBUG,  
  54. ); 
  55.  
  56.  
  57. /** 
  58. * Validate a level string. 
  59. * @param string $level 
  60. * @return bool True if $level is a valid level. 
  61. */ 
  62. public static function is_valid_level( $level ) { 
  63. return array_key_exists( strtolower( $level ), self::$level_to_severity ); 
  64.  
  65. /** 
  66. * Translate level string to integer. 
  67. * @param string $level emergency|alert|critical|error|warning|notice|info|debug 
  68. * @return int 100 (debug) - 800 (emergency) or 0 if not recognized 
  69. */ 
  70. public static function get_level_severity( $level ) { 
  71. if ( self::is_valid_level( $level ) ) { 
  72. $severity = self::$level_to_severity[ strtolower( $level ) ]; 
  73. } else { 
  74. $severity = 0; 
  75. return $severity; 
  76.  
  77. /** 
  78. * Translate severity integer to level string. 
  79. * @param int $severity 
  80. * @return bool|string False if not recognized. Otherwise string representation of level. 
  81. */ 
  82. public static function get_severity_level( $severity ) { 
  83. if ( array_key_exists( $severity, self::$severity_to_level ) ) { 
  84. return self::$severity_to_level[ $severity ]; 
  85. } else { 
  86. return false; 
  87.