abstracts
2 years ago
admin
2 years ago
elementor
4 years ago
export
3 years ago
fields
2 years ago
interfaces
8 years ago
libraries
2 years ago
log-handlers
4 years ago
shortcodes
2 years ago
stats
3 years ago
templates
5 years ago
class-everest-forms.php
2 years ago
class-evf-ajax.php
2 years ago
class-evf-autoloader.php
7 years ago
class-evf-background-updater.php
7 years ago
class-evf-cache-helper.php
6 years ago
class-evf-cron.php
3 years ago
class-evf-deprecated-action-hooks.php
6 years ago
class-evf-deprecated-filter-hooks.php
5 years ago
class-evf-emails.php
2 years ago
class-evf-fields.php
2 years ago
class-evf-form-block.php
4 years ago
class-evf-form-handler.php
3 years ago
class-evf-form-task.php
2 years ago
class-evf-forms-features.php
2 years ago
class-evf-frontend-scripts.php
2 years ago
class-evf-install.php
2 years ago
class-evf-integrations.php
7 years ago
class-evf-log-levels.php
8 years ago
class-evf-logger.php
5 years ago
class-evf-post-types.php
5 years ago
class-evf-privacy.php
6 years ago
class-evf-session-handler.php
7 years ago
class-evf-shortcodes.php
4 years ago
class-evf-smart-tags.php
2 years ago
class-evf-template-loader.php
2 years ago
class-evf-validation.php
6 years ago
evf-conditional-functions.php
6 years ago
evf-core-functions.php
2 years ago
evf-deprecated-functions.php
6 years ago
evf-entry-functions.php
3 years ago
evf-formatting-functions.php
4 years ago
evf-notice-functions.php
4 years ago
evf-template-functions.php
4 years ago
evf-template-hooks.php
7 years ago
evf-update-functions.php
5 years ago
class-evf-log-levels.php
113 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Standard log levels |
| 4 | * |
| 5 | * @version 1.0.0 |
| 6 | * @package EverestForms/Classes |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Log levels class. |
| 13 | */ |
| 14 | abstract class EVF_Log_Levels { |
| 15 | |
| 16 | /** |
| 17 | * Log Levels |
| 18 | * |
| 19 | * Description of levels: |
| 20 | * 'emergency': System is unusable. |
| 21 | * 'alert': Action must be taken immediately. |
| 22 | * 'critical': Critical conditions. |
| 23 | * 'error': Error conditions. |
| 24 | * 'warning': Warning conditions. |
| 25 | * 'notice': Normal but significant condition. |
| 26 | * 'info': Informational messages. |
| 27 | * 'debug': Debug-level messages. |
| 28 | * |
| 29 | * @see @link {https://tools.ietf.org/html/rfc5424} |
| 30 | */ |
| 31 | const EMERGENCY = 'emergency'; |
| 32 | const ALERT = 'alert'; |
| 33 | const CRITICAL = 'critical'; |
| 34 | const ERROR = 'error'; |
| 35 | const WARNING = 'warning'; |
| 36 | const NOTICE = 'notice'; |
| 37 | const INFO = 'info'; |
| 38 | const DEBUG = 'debug'; |
| 39 | |
| 40 | /** |
| 41 | * Level strings mapped to integer severity. |
| 42 | * |
| 43 | * @var array |
| 44 | */ |
| 45 | protected static $level_to_severity = array( |
| 46 | self::EMERGENCY => 800, |
| 47 | self::ALERT => 700, |
| 48 | self::CRITICAL => 600, |
| 49 | self::ERROR => 500, |
| 50 | self::WARNING => 400, |
| 51 | self::NOTICE => 300, |
| 52 | self::INFO => 200, |
| 53 | self::DEBUG => 100, |
| 54 | ); |
| 55 | |
| 56 | /** |
| 57 | * Severity integers mapped to level strings. |
| 58 | * |
| 59 | * This is the inverse of $level_severity. |
| 60 | * |
| 61 | * @var array |
| 62 | */ |
| 63 | protected static $severity_to_level = array( |
| 64 | 800 => self::EMERGENCY, |
| 65 | 700 => self::ALERT, |
| 66 | 600 => self::CRITICAL, |
| 67 | 500 => self::ERROR, |
| 68 | 400 => self::WARNING, |
| 69 | 300 => self::NOTICE, |
| 70 | 200 => self::INFO, |
| 71 | 100 => self::DEBUG, |
| 72 | ); |
| 73 | |
| 74 | /** |
| 75 | * Validate a level string. |
| 76 | * |
| 77 | * @param string $level Log level. |
| 78 | * @return bool True if $level is a valid level. |
| 79 | */ |
| 80 | public static function is_valid_level( $level ) { |
| 81 | return array_key_exists( strtolower( $level ), self::$level_to_severity ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Translate level string to integer. |
| 86 | * |
| 87 | * @param string $level Log level, options: emergency|alert|critical|error|warning|notice|info|debug. |
| 88 | * @return int 100 (debug) - 800 (emergency) or 0 if not recognized |
| 89 | */ |
| 90 | public static function get_level_severity( $level ) { |
| 91 | if ( self::is_valid_level( $level ) ) { |
| 92 | $severity = self::$level_to_severity[ strtolower( $level ) ]; |
| 93 | } else { |
| 94 | $severity = 0; |
| 95 | } |
| 96 | return $severity; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Translate severity integer to level string. |
| 101 | * |
| 102 | * @param int $severity Serevity level. |
| 103 | * @return bool|string False if not recognized. Otherwise string representation of level. |
| 104 | */ |
| 105 | public static function get_severity_level( $severity ) { |
| 106 | if ( array_key_exists( $severity, self::$severity_to_level ) ) { |
| 107 | return self::$severity_to_level[ $severity ]; |
| 108 | } else { |
| 109 | return false; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 |