@@ -73,6 +73,9 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
| 76 | + /** |
|
| 77 | + * @param string $class_name |
|
| 78 | + */ |
|
| 76 | 79 | public static function get_logger( $class_name ) { |
| 77 | 80 | |
| 78 | 81 | return new Wordlift_Log_Service( $class_name ); |
@@ -119,6 +122,9 @@ discard block |
||
| 119 | 122 | |
| 120 | 123 | } |
| 121 | 124 | |
| 125 | + /** |
|
| 126 | + * @param Exception $exception |
|
| 127 | + */ |
|
| 122 | 128 | public function error( $message, $exception = null ) { |
| 123 | 129 | |
| 124 | 130 | $this->log( self::ERROR, $message ); |
@@ -7,146 +7,146 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Log_Service { |
| 9 | 9 | |
| 10 | - const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s'; |
|
| 11 | - |
|
| 12 | - const ERROR = 4; |
|
| 13 | - const WARN = 3; |
|
| 14 | - const INFO = 2; |
|
| 15 | - const DEBUG = 1; |
|
| 16 | - const TRACE = 0; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * The class related to the logs. |
|
| 20 | - * |
|
| 21 | - * @since 1.0.0 |
|
| 22 | - * @access private |
|
| 23 | - * @var string $class_name The class related to the logs. |
|
| 24 | - */ |
|
| 25 | - private $class_name; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * The log levels for printing in log lines. |
|
| 29 | - * |
|
| 30 | - * @var array $levels An array of log levels. |
|
| 31 | - */ |
|
| 32 | - private static $levels = array( |
|
| 33 | - self::TRACE => 'TRACE', |
|
| 34 | - self::DEBUG => 'DEBUG', |
|
| 35 | - self::INFO => 'INFO', |
|
| 36 | - self::WARN => 'WARN', |
|
| 37 | - self::ERROR => 'ERROR', |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * A singleton instance for legacy logging. |
|
| 42 | - * |
|
| 43 | - * @since 3.10.0 |
|
| 44 | - * @access private |
|
| 45 | - * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging. |
|
| 46 | - */ |
|
| 47 | - private static $instance = null; |
|
| 10 | + const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s'; |
|
| 11 | + |
|
| 12 | + const ERROR = 4; |
|
| 13 | + const WARN = 3; |
|
| 14 | + const INFO = 2; |
|
| 15 | + const DEBUG = 1; |
|
| 16 | + const TRACE = 0; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * The class related to the logs. |
|
| 20 | + * |
|
| 21 | + * @since 1.0.0 |
|
| 22 | + * @access private |
|
| 23 | + * @var string $class_name The class related to the logs. |
|
| 24 | + */ |
|
| 25 | + private $class_name; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * The log levels for printing in log lines. |
|
| 29 | + * |
|
| 30 | + * @var array $levels An array of log levels. |
|
| 31 | + */ |
|
| 32 | + private static $levels = array( |
|
| 33 | + self::TRACE => 'TRACE', |
|
| 34 | + self::DEBUG => 'DEBUG', |
|
| 35 | + self::INFO => 'INFO', |
|
| 36 | + self::WARN => 'WARN', |
|
| 37 | + self::ERROR => 'ERROR', |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * A singleton instance for legacy logging. |
|
| 42 | + * |
|
| 43 | + * @since 3.10.0 |
|
| 44 | + * @access private |
|
| 45 | + * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging. |
|
| 46 | + */ |
|
| 47 | + private static $instance = null; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Create an instance of the Log service. |
|
| 51 | - * |
|
| 52 | - * @param string $class_name The class related to the logs. |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * |
|
| 56 | - */ |
|
| 57 | - public function __construct( $class_name ) { |
|
| 49 | + /** |
|
| 50 | + * Create an instance of the Log service. |
|
| 51 | + * |
|
| 52 | + * @param string $class_name The class related to the logs. |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * |
|
| 56 | + */ |
|
| 57 | + public function __construct( $class_name ) { |
|
| 58 | 58 | |
| 59 | - $this->class_name = $class_name; |
|
| 59 | + $this->class_name = $class_name; |
|
| 60 | 60 | |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Get the ROOT logger. |
|
| 65 | - * |
|
| 66 | - * @return \Wordlift_Log_Service A singleton instance for legacy logging. |
|
| 67 | - * @since 3.10.0 |
|
| 68 | - * |
|
| 69 | - */ |
|
| 70 | - public static function get_instance() { |
|
| 63 | + /** |
|
| 64 | + * Get the ROOT logger. |
|
| 65 | + * |
|
| 66 | + * @return \Wordlift_Log_Service A singleton instance for legacy logging. |
|
| 67 | + * @since 3.10.0 |
|
| 68 | + * |
|
| 69 | + */ |
|
| 70 | + public static function get_instance() { |
|
| 71 | 71 | |
| 72 | - return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
| 73 | - } |
|
| 72 | + return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - public static function get_logger( $class_name ) { |
|
| 76 | + public static function get_logger( $class_name ) { |
|
| 77 | 77 | |
| 78 | - return new Wordlift_Log_Service( $class_name ); |
|
| 78 | + return new Wordlift_Log_Service( $class_name ); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Log a message. |
|
| 84 | - * |
|
| 85 | - * @param string $level The log level. |
|
| 86 | - * @param string $message The message to log. |
|
| 87 | - * |
|
| 88 | - * @since 1.0.0 |
|
| 89 | - * |
|
| 90 | - */ |
|
| 91 | - public function log( $level, $message ) { |
|
| 82 | + /** |
|
| 83 | + * Log a message. |
|
| 84 | + * |
|
| 85 | + * @param string $level The log level. |
|
| 86 | + * @param string $message The message to log. |
|
| 87 | + * |
|
| 88 | + * @since 1.0.0 |
|
| 89 | + * |
|
| 90 | + */ |
|
| 91 | + public function log( $level, $message ) { |
|
| 92 | 92 | |
| 93 | - // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
| 93 | + // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
| 94 | 94 | |
| 95 | - // Bail out if `WL_DEBUG` isn't defined or it's false. |
|
| 96 | - if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 95 | + // Bail out if `WL_DEBUG` isn't defined or it's false. |
|
| 96 | + if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
|
| 101 | - if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
| 102 | - && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
| 103 | - return; |
|
| 104 | - } |
|
| 100 | + // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
|
| 101 | + if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
| 102 | + && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - // Bail out if the log message is below the minimum log level. |
|
| 107 | - if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 106 | + // Bail out if the log message is below the minimum log level. |
|
| 107 | + if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - // Bail out if there's a filter and we don't match it. |
|
| 112 | - $class_name = wp_slash( $this->class_name ); |
|
| 113 | - if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 111 | + // Bail out if there's a filter and we don't match it. |
|
| 112 | + $class_name = wp_slash( $this->class_name ); |
|
| 113 | + if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - // Finally log the message. |
|
| 118 | - error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
| 117 | + // Finally log the message. |
|
| 118 | + error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
| 119 | 119 | |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - public function error( $message, $exception = null ) { |
|
| 122 | + public function error( $message, $exception = null ) { |
|
| 123 | 123 | |
| 124 | - $this->log( self::ERROR, $message ); |
|
| 124 | + $this->log( self::ERROR, $message ); |
|
| 125 | 125 | |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - public function warn( $message ) { |
|
| 128 | + public function warn( $message ) { |
|
| 129 | 129 | |
| 130 | - $this->log( self::WARN, $message ); |
|
| 130 | + $this->log( self::WARN, $message ); |
|
| 131 | 131 | |
| 132 | - } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - public function info( $message ) { |
|
| 134 | + public function info( $message ) { |
|
| 135 | 135 | |
| 136 | - $this->log( self::INFO, $message ); |
|
| 136 | + $this->log( self::INFO, $message ); |
|
| 137 | 137 | |
| 138 | - } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public function debug( $message ) { |
|
| 140 | + public function debug( $message ) { |
|
| 141 | 141 | |
| 142 | - $this->log( self::DEBUG, $message ); |
|
| 142 | + $this->log( self::DEBUG, $message ); |
|
| 143 | 143 | |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - public function trace( $message ) { |
|
| 146 | + public function trace( $message ) { |
|
| 147 | 147 | |
| 148 | - $this->log( self::TRACE, $message ); |
|
| 148 | + $this->log( self::TRACE, $message ); |
|
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @since 1.0.0 |
| 55 | 55 | * |
| 56 | 56 | */ |
| 57 | - public function __construct( $class_name ) { |
|
| 57 | + public function __construct($class_name) { |
|
| 58 | 58 | |
| 59 | 59 | $this->class_name = $class_name; |
| 60 | 60 | |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public static function get_instance() { |
| 71 | 71 | |
| 72 | - return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' ); |
|
| 72 | + return self::$instance ?: self::$instance = new Wordlift_Log_Service('ROOT'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
| 76 | - public static function get_logger( $class_name ) { |
|
| 76 | + public static function get_logger($class_name) { |
|
| 77 | 77 | |
| 78 | - return new Wordlift_Log_Service( $class_name ); |
|
| 78 | + return new Wordlift_Log_Service($class_name); |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,64 +88,64 @@ discard block |
||
| 88 | 88 | * @since 1.0.0 |
| 89 | 89 | * |
| 90 | 90 | */ |
| 91 | - public function log( $level, $message ) { |
|
| 91 | + public function log($level, $message) { |
|
| 92 | 92 | |
| 93 | 93 | // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
| 94 | 94 | |
| 95 | 95 | // Bail out if `WL_DEBUG` isn't defined or it's false. |
| 96 | - if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) { |
|
| 96 | + if ( ! defined('WL_DEBUG') || false === WL_DEBUG) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
| 101 | - if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR |
|
| 102 | - && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
|
| 101 | + if ( ! defined('WL_LOG_LEVEL') && $level < self::ERROR |
|
| 102 | + && ( ! defined('WP_DEBUG') || false === WP_DEBUG)) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Bail out if the log message is below the minimum log level. |
| 107 | - if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
|
| 107 | + if (defined('WL_LOG_LEVEL') && $level < intval(WL_LOG_LEVEL)) { |
|
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // Bail out if there's a filter and we don't match it. |
| 112 | - $class_name = wp_slash( $this->class_name ); |
|
| 113 | - if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) { |
|
| 112 | + $class_name = wp_slash($this->class_name); |
|
| 113 | + if (defined('WL_LOG_FILTER') && 1 !== preg_match("/(^|,)$class_name($|,)/", WL_LOG_FILTER)) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Finally log the message. |
| 118 | - error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
|
| 118 | + error_log(sprintf(self::MESSAGE_TEMPLATE, self::$levels[$level], $this->class_name, is_array($message) ? implode(', ', $message) : $message)); |
|
| 119 | 119 | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function error( $message, $exception = null ) { |
|
| 122 | + public function error($message, $exception = null) { |
|
| 123 | 123 | |
| 124 | - $this->log( self::ERROR, $message ); |
|
| 124 | + $this->log(self::ERROR, $message); |
|
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function warn( $message ) { |
|
| 128 | + public function warn($message) { |
|
| 129 | 129 | |
| 130 | - $this->log( self::WARN, $message ); |
|
| 130 | + $this->log(self::WARN, $message); |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public function info( $message ) { |
|
| 134 | + public function info($message) { |
|
| 135 | 135 | |
| 136 | - $this->log( self::INFO, $message ); |
|
| 136 | + $this->log(self::INFO, $message); |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public function debug( $message ) { |
|
| 140 | + public function debug($message) { |
|
| 141 | 141 | |
| 142 | - $this->log( self::DEBUG, $message ); |
|
| 142 | + $this->log(self::DEBUG, $message); |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function trace( $message ) { |
|
| 146 | + public function trace($message) { |
|
| 147 | 147 | |
| 148 | - $this->log( self::TRACE, $message ); |
|
| 148 | + $this->log(self::TRACE, $message); |
|
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |