| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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); |
||
| 148 | public function __construct(string $format = null, LogEntryFactoryInterface $factory = null) |
||
| 149 | { |
||
| 150 | $this->software = 'Apache'; |
||
| 151 | $this->prettyName = 'Apache Error'; |
||
| 152 | $this->defaultFormat = self::FORMAT_APACHE_2_4_DEFAULT; |
||
| 153 | |||
| 154 | // set 2.2 format by default. Will be changed to 2.4 format, ie: |
||
| 155 | // $this->timeFormat = 'D M d H:i:s.u Y'; |
||
| 156 | // , if the format contain %{u} insted of %t |
||
| 157 | $this->timeFormat = 'D M d H:i:s Y'; |
||
| 158 | |||
| 159 | $this->addFormat('default', self::FORMAT_APACHE_2_4_DEFAULT); |
||
| 160 | $this->addFormat('apache2.2 default', self::FORMAT_APACHE_2_2_DEFAULT); |
||
| 161 | $this->addFormat('apache2.2 extented', self::FORMAT_APACHE_2_2_EXTENDED); |
||
| 162 | $this->addFormat('apache2.2 referer', self::FORMAT_APACHE_2_2_REFERER); |
||
| 163 | $this->addFormat('apache2.2 extented referer', self::FORMAT_APACHE_2_2_EXTENDED_REFERER); |
||
| 164 | $this->addFormat('apache2.4 default', self::FORMAT_APACHE_2_4_DEFAULT); |
||
| 165 | $this->addFormat('apache2.4 extented', self::FORMAT_APACHE_2_4_EXTENDED); |
||
| 166 | $this->addFormat('apache2.4 referer', self::FORMAT_APACHE_2_4_REFEFER); |
||
| 167 | $this->addFormat('apache2.4 extented referer', self::FORMAT_APACHE_2_4_EXTENDED_REFERER); |
||
| 168 | $this->addFormat('apache2.4 npm', self::FORMAT_APACHE_2_4_MPM); |
||
| 169 | $this->addFormat('apache2.4 npm extented', self::FORMAT_APACHE_2_4_MPM_EXTENDED); |
||
| 170 | $this->addFormat('apache2.4 npm referer', self::FORMAT_APACHE_2_4_MPM_REFERER); |
||
| 171 | $this->addFormat('apache2.4 npm extented referer ', self::FORMAT_APACHE_2_4_MPM_EXTENDED_REFERER); |
||
| 172 | $this->addFormat('apache2.4 npm tid', self::FORMAT_APACHE_2_4_MPM_TID); |
||
| 173 | $this->addFormat('apache2.4 npm tid referer', self::FORMAT_APACHE_2_4_MPM_TID_REFERER); |
||
| 174 | |||
| 175 | $this->addPath("/var/log/"); |
||
| 176 | $this->addPath("/var/log/apache/"); |
||
| 177 | $this->addPath("/var/log/apache2/"); |
||
| 178 | $this->addPath("/var/log/httpd/"); |
||
| 179 | $this->addPath("/usr/local/var/log/apache/"); |
||
| 180 | $this->addPath("/usr/local/var/log/apache2/"); |
||
| 181 | $this->addPath("/usr/local/var/log/httpd/"); |
||
| 182 | $this->addPath("/opt/local/apache/logs/"); |
||
| 183 | $this->addPath("/opt/local/apache2/logs/"); |
||
| 184 | $this->addPath("/opt/local/httpd/logs/"); |
||
| 185 | $this->addPath("C:/wamp/logs/"); |
||
| 186 | |||
| 187 | $this->addFile('error.log'); |
||
| 188 | $this->addFile('error_log'); |
||
| 189 | $this->addFile("apache_error.log"); |
||
| 190 | |||
| 191 | // *************** |
||
| 192 | // define patterns |
||
| 193 | // *************** |
||
| 194 | |||
| 195 | $this->addNamedPattern('%%' , 'percent', '\%'); |
||
| 196 | |||
| 197 | // %t The current time |
||
| 198 | // %{u}t The current time including micro-seconds |
||
| 199 | $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})\]'; |
||
| 200 | $this->addPattern('\[%{u}t\]', $datePattern); |
||
| 201 | $this->addPattern('\[%t\]', $datePattern); |
||
| 202 | $this->addPattern('%t', $datePattern); |
||
| 203 | |||
| 204 | // %a Client IP address and port of the request (port is not registered by parser). |
||
| 205 | // That column may be missing depending of error |
||
| 206 | $clientIpPattern = '( \[client (?P<remoteIp>' . self::PATTERN_IP_ALL . ')(:[\d]+|)?\])?'; |
||
| 207 | $this->addPattern(' \[client %a\]' , $clientIpPattern); |
||
| 208 | $this->addPattern(' \[%a\]' , $clientIpPattern); |
||
| 209 | $this->addPattern(' %a' , $clientIpPattern); |
||
| 210 | |||
| 211 | // %A Local IP-address and port |
||
| 212 | // That column may be missing depending of error |
||
| 213 | $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); |
||
| 214 | |||
| 215 | // %m Name of the module logging the message |
||
| 216 | // %l Loglevel of the message |
||
| 217 | $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 218 | $this->addPattern('\[%-m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 219 | $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); |
||
| 220 | $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); |
||
| 221 | |||
| 222 | // %P Process ID of current process (since apache 2.4?) |
||
| 223 | // %T Thread ID of current thread |
||
| 224 | $this->addPattern('\[pid %P:tid %T\]', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 225 | $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 226 | $this->addPattern('\[pid %P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 227 | $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 228 | $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); |
||
| 229 | |||
| 230 | // %E APR/OS error status code and string |
||
| 231 | // That column may be missing depending of error |
||
| 232 | $this->addPattern(' %E:', '( (?P<errorCode>\([\-\d]+\)[^\[]+):)?'); |
||
| 233 | |||
| 234 | // %F Source file name and line number of the log call |
||
| 235 | //$this->addPattern(' %F:', '( (?P<fileName>[^\*\s\|><\?]*[\/][^\*\s\|><\?]*):)?'); |
||
| 236 | $this->addPattern(' %F:', '( (?P<fileName>[^ ]+\([\d]+\)):)?'); |
||
| 237 | |||
| 238 | // %M The actual log message |
||
| 239 | $this->addNamedPattern('%M', 'message', '.+?'); |
||
| 240 | |||
| 241 | // referer (may be empty) |
||
| 242 | $this->addPattern(' , referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); |
||
| 243 | $this->addPattern(', referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); |
||
| 244 | |||
| 245 | // now let default constructor |
||
| 246 | parent::__construct($format, $factory); |
||
| 247 | } |
||
| 266 | } |