Completed
Push — develop ( 3a945b...f7f2e7 )
by David
02:47
created
src/includes/class-wordlift-log-service.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -71,6 +71,9 @@
 block discarded – undo
71 71
 	}
72 72
 
73 73
 
74
+	/**
75
+	 * @param string $class_name
76
+	 */
74 77
 	public static function get_logger( $class_name ) {
75 78
 
76 79
 		return new Wordlift_Log_Service( $class_name );
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -7,143 +7,143 @@
 block discarded – undo
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
-	);
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 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;
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
-	 * @since 1.0.0
52
-	 *
53
-	 * @param string $class_name The class related to the logs.
54
-	 */
55
-	public function __construct( $class_name ) {
49
+    /**
50
+     * Create an instance of the Log service.
51
+     * @since 1.0.0
52
+     *
53
+     * @param string $class_name The class related to the logs.
54
+     */
55
+    public function __construct( $class_name ) {
56 56
 
57
-		$this->class_name = $class_name;
57
+        $this->class_name = $class_name;
58 58
 
59
-	}
59
+    }
60 60
 
61
-	/**
62
-	 * Get the ROOT logger.
63
-	 *
64
-	 * @since 3.10.0
65
-	 *
66
-	 * @return \Wordlift_Log_Service A singleton instance for legacy logging.
67
-	 */
68
-	public static function get_instance() {
61
+    /**
62
+     * Get the ROOT logger.
63
+     *
64
+     * @since 3.10.0
65
+     *
66
+     * @return \Wordlift_Log_Service A singleton instance for legacy logging.
67
+     */
68
+    public static function get_instance() {
69 69
 
70
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
71
-	}
70
+        return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
71
+    }
72 72
 
73 73
 
74
-	public static function get_logger( $class_name ) {
74
+    public static function get_logger( $class_name ) {
75 75
 
76
-		return new Wordlift_Log_Service( $class_name );
76
+        return new Wordlift_Log_Service( $class_name );
77 77
 
78
-	}
78
+    }
79 79
 
80
-	/**
81
-	 * Log a message.
82
-	 *
83
-	 * @since 1.0.0
84
-	 *
85
-	 * @param string $level   The log level.
86
-	 * @param string $message The message to log.
87
-	 */
88
-	public function log( $level, $message ) {
80
+    /**
81
+     * Log a message.
82
+     *
83
+     * @since 1.0.0
84
+     *
85
+     * @param string $level   The log level.
86
+     * @param string $message The message to log.
87
+     */
88
+    public function log( $level, $message ) {
89 89
 
90
-		echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
90
+        echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
91 91
 
92
-		// Bail out if `WL_DEBUG` isn't defined or it's false.
93
-		if ( ! defined( 'WL_DEBUG') || false === WL_DEBUG ) {
94
-			return;
95
-		}
92
+        // Bail out if `WL_DEBUG` isn't defined or it's false.
93
+        if ( ! defined( 'WL_DEBUG') || false === WL_DEBUG ) {
94
+            return;
95
+        }
96 96
 
97
-		// Bail out if WordLift log level isn't defined, and WP debug is disabled.
98
-		if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
99
-			 && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
100
-			return;
101
-		}
97
+        // Bail out if WordLift log level isn't defined, and WP debug is disabled.
98
+        if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
99
+             && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
100
+            return;
101
+        }
102 102
 
103
-		// Bail out if the log message is below the minimum log level.
104
-		if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
105
-			return;
106
-		}
103
+        // Bail out if the log message is below the minimum log level.
104
+        if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
105
+            return;
106
+        }
107 107
 
108
-		// Bail out if there's a filter and we don't match it.
109
-		$class_name = wp_slash( $this->class_name );
110
-		if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
111
-			return;
112
-		}
108
+        // Bail out if there's a filter and we don't match it.
109
+        $class_name = wp_slash( $this->class_name );
110
+        if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
111
+            return;
112
+        }
113 113
 
114
-		// Finally log the message.
115
-		error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
114
+        // Finally log the message.
115
+        error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
116 116
 
117
-	}
117
+    }
118 118
 
119
-	public function error( $message ) {
119
+    public function error( $message ) {
120 120
 
121
-		$this->log( self::ERROR, $message );
121
+        $this->log( self::ERROR, $message );
122 122
 
123
-	}
123
+    }
124 124
 
125
-	public function warn( $message ) {
125
+    public function warn( $message ) {
126 126
 
127
-		$this->log( self::WARN, $message );
127
+        $this->log( self::WARN, $message );
128 128
 
129
-	}
129
+    }
130 130
 
131
-	public function info( $message ) {
131
+    public function info( $message ) {
132 132
 
133
-		$this->log( self::INFO, $message );
133
+        $this->log( self::INFO, $message );
134 134
 
135
-	}
135
+    }
136 136
 
137
-	public function debug( $message ) {
137
+    public function debug( $message ) {
138 138
 
139
-		$this->log( self::DEBUG, $message );
139
+        $this->log( self::DEBUG, $message );
140 140
 
141
-	}
141
+    }
142 142
 
143
-	public function trace( $message ) {
143
+    public function trace( $message ) {
144 144
 
145
-		$this->log( self::TRACE, $message );
145
+        $this->log( self::TRACE, $message );
146 146
 
147
-	}
147
+    }
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @param string $class_name The class related to the logs.
54 54
 	 */
55
-	public function __construct( $class_name ) {
55
+	public function __construct($class_name) {
56 56
 
57 57
 		$this->class_name = $class_name;
58 58
 
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public static function get_instance() {
69 69
 
70
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
70
+		return self::$instance ?: self::$instance = new Wordlift_Log_Service('ROOT');
71 71
 	}
72 72
 
73 73
 
74
-	public static function get_logger( $class_name ) {
74
+	public static function get_logger($class_name) {
75 75
 
76
-		return new Wordlift_Log_Service( $class_name );
76
+		return new Wordlift_Log_Service($class_name);
77 77
 
78 78
 	}
79 79
 
@@ -85,64 +85,64 @@  discard block
 block discarded – undo
85 85
 	 * @param string $level   The log level.
86 86
 	 * @param string $message The message to log.
87 87
 	 */
88
-	public function log( $level, $message ) {
88
+	public function log($level, $message) {
89 89
 
90
-		echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
90
+		echo(sprintf(self::MESSAGE_TEMPLATE."\n", self::$levels[$level], $this->class_name, is_array($message) ? implode(', ', $message) : $message));
91 91
 
92 92
 		// Bail out if `WL_DEBUG` isn't defined or it's false.
93
-		if ( ! defined( 'WL_DEBUG') || false === WL_DEBUG ) {
93
+		if ( ! defined('WL_DEBUG') || false === WL_DEBUG) {
94 94
 			return;
95 95
 		}
96 96
 
97 97
 		// Bail out if WordLift log level isn't defined, and WP debug is disabled.
98
-		if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
99
-			 && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
98
+		if ( ! defined('WL_LOG_LEVEL') && $level < self::ERROR
99
+			 && ( ! defined('WP_DEBUG') || false === WP_DEBUG)) {
100 100
 			return;
101 101
 		}
102 102
 
103 103
 		// Bail out if the log message is below the minimum log level.
104
-		if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
104
+		if (defined('WL_LOG_LEVEL') && $level < intval(WL_LOG_LEVEL)) {
105 105
 			return;
106 106
 		}
107 107
 
108 108
 		// Bail out if there's a filter and we don't match it.
109
-		$class_name = wp_slash( $this->class_name );
110
-		if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
109
+		$class_name = wp_slash($this->class_name);
110
+		if (defined('WL_LOG_FILTER') && 1 !== preg_match("/(^|,)$class_name($|,)/", WL_LOG_FILTER)) {
111 111
 			return;
112 112
 		}
113 113
 
114 114
 		// Finally log the message.
115
-		error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
115
+		error_log(sprintf(self::MESSAGE_TEMPLATE, self::$levels[$level], $this->class_name, is_array($message) ? implode(', ', $message) : $message));
116 116
 
117 117
 	}
118 118
 
119
-	public function error( $message ) {
119
+	public function error($message) {
120 120
 
121
-		$this->log( self::ERROR, $message );
121
+		$this->log(self::ERROR, $message);
122 122
 
123 123
 	}
124 124
 
125
-	public function warn( $message ) {
125
+	public function warn($message) {
126 126
 
127
-		$this->log( self::WARN, $message );
127
+		$this->log(self::WARN, $message);
128 128
 
129 129
 	}
130 130
 
131
-	public function info( $message ) {
131
+	public function info($message) {
132 132
 
133
-		$this->log( self::INFO, $message );
133
+		$this->log(self::INFO, $message);
134 134
 
135 135
 	}
136 136
 
137
-	public function debug( $message ) {
137
+	public function debug($message) {
138 138
 
139
-		$this->log( self::DEBUG, $message );
139
+		$this->log(self::DEBUG, $message);
140 140
 
141 141
 	}
142 142
 
143
-	public function trace( $message ) {
143
+	public function trace($message) {
144 144
 
145
-		$this->log( self::TRACE, $message );
145
+		$this->log(self::TRACE, $message);
146 146
 
147 147
 	}
148 148
 
Please login to merge, or discard this patch.