| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 173 | public function __construct(string $format = null, LogEntryFactoryInterface $factory = null) |
||
| 174 | { |
||
| 175 | $this->software = 'Apache'; |
||
| 176 | $this->prettyName = 'Apache Error'; |
||
| 177 | $this->defaultFormat = self::FORMAT_APACHE_2_4_DEFAULT; |
||
| 178 | |||
| 179 | // set 2.2 format by default. Will be changed to 2.4 format, ie: |
||
| 180 | // $this->timeFormat = 'D M d H:i:s.u Y'; |
||
| 181 | // , if the format contains %{u} instead of %t |
||
| 182 | $this->timeFormat = 'D M d H:i:s Y'; |
||
| 183 | |||
| 184 | $this->addFormat('default', self::FORMAT_APACHE_2_4_DEFAULT); |
||
| 185 | $this->addFormat('apache2.2 default', self::FORMAT_APACHE_2_2_DEFAULT); |
||
| 186 | $this->addFormat('apache2.2 extented', self::FORMAT_APACHE_2_2_EXTENDED); |
||
| 187 | $this->addFormat('apache2.2 referer', self::FORMAT_APACHE_2_2_REFERER); |
||
| 188 | $this->addFormat('apache2.2 extented referer', self::FORMAT_APACHE_2_2_EXTENDED_REFERER); |
||
| 189 | $this->addFormat('apache2.4 default', self::FORMAT_APACHE_2_4_DEFAULT); |
||
| 190 | $this->addFormat('apache2.4 extented', self::FORMAT_APACHE_2_4_EXTENDED); |
||
| 191 | $this->addFormat('apache2.4 referer', self::FORMAT_APACHE_2_4_REFEFER); |
||
| 192 | $this->addFormat('apache2.4 extented referer', self::FORMAT_APACHE_2_4_EXTENDED_REFERER); |
||
| 193 | $this->addFormat('apache2.4 mpm', self::FORMAT_APACHE_2_4_MPM); |
||
| 194 | $this->addFormat('apache2.4 mpm extented', self::FORMAT_APACHE_2_4_MPM_EXTENDED); |
||
| 195 | $this->addFormat('apache2.4 mpm referer', self::FORMAT_APACHE_2_4_MPM_REFERER); |
||
| 196 | $this->addFormat('apache2.4 mpm extented referer ', self::FORMAT_APACHE_2_4_MPM_EXTENDED_REFERER); |
||
| 197 | $this->addFormat('apache2.4 mpm tid', self::FORMAT_APACHE_2_4_MPM_TID); |
||
| 198 | $this->addFormat('apache2.4 mpm tid referer', self::FORMAT_APACHE_2_4_MPM_TID_REFERER); |
||
| 199 | |||
| 200 | $this->addPath("/var/log/"); |
||
| 201 | $this->addPath("/var/log/apache/"); |
||
| 202 | $this->addPath("/var/log/apache2/"); |
||
| 203 | $this->addPath("/var/log/httpd/"); |
||
| 204 | $this->addPath("/usr/local/var/log/apache/"); |
||
| 205 | $this->addPath("/usr/local/var/log/apache2/"); |
||
| 206 | $this->addPath("/usr/local/var/log/httpd/"); |
||
| 207 | $this->addPath("/opt/local/apache/logs/"); |
||
| 208 | $this->addPath("/opt/local/apache2/logs/"); |
||
| 209 | $this->addPath("/opt/local/httpd/logs/"); |
||
| 210 | $this->addPath("C:/wamp/logs/"); |
||
| 211 | |||
| 212 | $this->addFile('error.log'); |
||
| 213 | $this->addFile('error_log'); |
||
| 214 | $this->addFile("apache_error.log"); |
||
| 215 | |||
| 216 | // *************** |
||
| 217 | // define patterns |
||
| 218 | // *************** |
||
| 219 | |||
| 220 | $this->addNamedPattern('%%' , 'percent', '\%'); |
||
| 221 | |||
| 222 | // %t The current time |
||
| 223 | // %{u}t The current time including micro-seconds |
||
| 224 | $datePattern = '\[(?P<time>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2} \d{2}:\d{2}:\d{2}(?:\.\d{6}|) \d{4})\]'; |
||
| 225 | $this->addPattern('\[%{u}t\]', $datePattern); |
||
| 226 | $this->addPattern('\[%t\]', $datePattern); |
||
| 227 | $this->addPattern('%t', $datePattern); |
||
| 228 | |||
| 229 | // %a Client IP address and port of the request (port is not registered by parser). |
||
| 230 | // That column may be missing depending of error |
||
| 231 | $clientIpPattern = '( \[client (?P<remoteIp>' . self::PATTERN_IP_ALL . ')(:[\d]+|)?\])?'; |
||
| 232 | $this->addPattern(' \[client %a\]' , $clientIpPattern); |
||
| 233 | $this->addPattern(' \[%a\]' , $clientIpPattern); |
||
| 234 | $this->addPattern(' %a' , $clientIpPattern); |
||
| 235 | |||
| 236 | // %A Local IP-address and port |
||
| 237 | // That column may be missing depending of error |
||
| 238 | $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); |
||
| 239 | |||
| 240 | // %m Name of the module logging the message |
||
| 241 | // %l Loglevel of the message |
||
| 242 | $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 243 | $this->addPattern('\[%-m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 244 | $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); |
||
| 245 | $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); |
||
| 246 | |||
| 247 | // %P Process ID of current process (since apache 2.4?) |
||
| 248 | // %T Thread ID of current thread |
||
| 249 | $this->addPattern('\[pid %P:tid %T\]', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 250 | $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 251 | $this->addPattern('\[pid %P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 252 | $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 253 | $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); |
||
| 254 | |||
| 255 | // %E APR/OS error status code and string |
||
| 256 | // That column may be missing depending of error |
||
| 257 | $this->addPattern(' %E:', '( (?P<errorCode>\([\-\d]+\)[^\[]+):)?'); |
||
| 258 | |||
| 259 | // %F Source file name and line number of the log call |
||
| 260 | //$this->addPattern(' %F:', '( (?P<fileName>[^\*\s\|><\?]*[\/][^\*\s\|><\?]*):)?'); |
||
| 261 | $this->addPattern(' %F:', '( (?P<fileName>[^ ]+\([\d]+\)):)?'); |
||
| 262 | |||
| 263 | // %M The actual log message |
||
| 264 | $this->addNamedPattern('%M', 'message', '.+?'); |
||
| 265 | |||
| 266 | // referer (may be empty) |
||
| 267 | $this->addPattern(' , referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); |
||
| 268 | $this->addPattern(', referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); |
||
| 269 | |||
| 270 | // now let default constructor |
||
| 271 | parent::__construct($format, $factory); |
||
| 272 | } |
||
| 291 | } |