12
12
*/
13
13
class Log {
14
14
15
+ public static const NONE = 'none ' ;
16
+ public static const DEBUG = 'debug ' ;
17
+ public static const INFO = 'info ' ;
18
+ public static const WARN = 'warn ' ;
19
+ public static const ERROR = 'error ' ;
20
+
15
21
/** The available log priorities */
16
22
protected static $ logPriorities ;
17
23
/** The log level to issue in error_log */
@@ -29,7 +35,7 @@ class Log {
29
35
*/
30
36
public static function instance () {
31
37
if (self ::$ logLevel == null ) {
32
- self ::$ logLevel == ' info ' ;
38
+ self ::$ logLevel == INFO ;
33
39
}
34
40
if (self ::$ instance == null ) {
35
41
self ::$ instance = new Log ();
@@ -103,7 +109,7 @@ public function getStackTrace($excludeFile = NULL) {
103
109
* @param mixed $o - an oject to be dumped along with message. An Exception object will cause a stacktrace dump (optional).
104
110
*/
105
111
public static function debug ($ s , $ o = null ) {
106
- self ::instance ()->log (' debug ' , $ s , $ o );
112
+ self ::instance ()->log (DEBUG , $ s , $ o );
107
113
}
108
114
109
115
/**
@@ -112,7 +118,7 @@ public static function debug($s, $o = null) {
112
118
* @param mixed $o - an oject to be dumped along with message. An Exception object will cause a stacktrace dump (optional).
113
119
*/
114
120
public static function info ($ s , $ o = null ) {
115
- self ::instance ()->log (' info ' , $ s , $ o );
121
+ self ::instance ()->log (INFO , $ s , $ o );
116
122
}
117
123
118
124
/**
@@ -121,7 +127,7 @@ public static function info($s, $o = null) {
121
127
* @param mixed $o - an oject to be dumped along with message. An Exception object will cause a stacktrace dump (optional).
122
128
*/
123
129
public static function warn ($ s , $ o = null ) {
124
- self ::instance ()->log (' warn ' , $ s , $ o );
130
+ self ::instance ()->log (WARN , $ s , $ o );
125
131
}
126
132
127
133
/**
@@ -130,39 +136,39 @@ public static function warn($s, $o = null) {
130
136
* @param mixed $o - an oject to be dumped along with message. An Exception object will cause a stacktrace dump (optional).
131
137
*/
132
138
public static function error ($ s , $ o = null ) {
133
- self ::instance ()->log (' error ' , $ s , $ o );
139
+ self ::instance ()->log (ERROR , $ s , $ o );
134
140
}
135
141
136
142
/**
137
143
* Print stacktrace into debug log, optionally excluding a certain file from trace.
138
144
* @param string $excludeFile - the file to be excluded (optional).
139
145
*/
140
146
public static function debugStackTrace ($ excludeFile = NULL ) {
141
- self ::instance ()->logStackTrace (' debug ' , $ excludeFile );
147
+ self ::instance ()->logStackTrace (DEBUG , $ excludeFile );
142
148
}
143
149
144
150
/**
145
151
* Print stacktrace into info log, optionally excluding a certain file from trace.
146
152
* @param string $excludeFile - the file to be excluded (optional).
147
153
*/
148
154
public static function infoStackTrace ($ excludeFile = NULL ) {
149
- self ::instance ()->logStackTrace (' info ' , $ excludeFile );
155
+ self ::instance ()->logStackTrace (INFO , $ excludeFile );
150
156
}
151
157
152
158
/**
153
159
* Print stacktrace into warning log, optionally excluding a certain file from trace.
154
160
* @param string $excludeFile - the file to be excluded (optional).
155
161
*/
156
162
public static function warnStackTrace ($ excludeFile = NULL ) {
157
- self ::instance ()->logStackTrace (' warn ' , $ excludeFile );
163
+ self ::instance ()->logStackTrace (WARN , $ excludeFile );
158
164
}
159
165
160
166
/**
161
167
* Print stacktrace into error log, optionally excluding a certain file from trace.
162
168
* @param string $excludeFile - the file to be excluded (optional).
163
169
*/
164
170
public static function errorStackTrace ($ excludeFile = NULL ) {
165
- self ::instance ()->logStackTrace (' error ' , $ excludeFile );
171
+ self ::instance ()->logStackTrace (ERROR , $ excludeFile );
166
172
}
167
173
168
174
/**
@@ -210,7 +216,7 @@ public static function get() {
210
216
*/
211
217
protected static function isLogLevelIncluded ($ sev ) {
212
218
if (self ::$ logPriorities == null ) {
213
- self ::$ logPriorities = array (' none ' , ' debug ' , ' info ' , ' warning ' , ' error ' );
219
+ self ::$ logPriorities = array (NONE , DEBUG , INFO , WARN , ERROR );
214
220
}
215
221
$ logIndex = array_search (self ::$ logLevel , self ::$ logPriorities );
216
222
$ sevIndex = array_search ($ sev , self ::$ logPriorities );
0 commit comments