| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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); |
||
| 94 | public function __construct(string $format = null, LogEntryFactoryInterface $factory = null) |
||
| 95 | { |
||
| 96 | $this->software = 'Apache'; |
||
| 97 | $this->prettyName = 'Apache Error'; |
||
| 98 | $this->defaultFormat = self::FORMAT_DEFAULT_APACHE_2_4; |
||
| 99 | |||
| 100 | // 2.2 / 2.4 |
||
| 101 | $this->timeFormat = 'D M d H:i:s Y'; |
||
| 102 | //$this->timeFormat = 'D M d H:i:s.u Y'; |
||
| 103 | |||
| 104 | $this->addFormat('default', self::FORMAT_DEFAULT_APACHE_2_4); |
||
| 105 | |||
| 106 | $this->addPath("/var/log/"); |
||
| 107 | $this->addPath("/var/log/apache/"); |
||
| 108 | $this->addPath("/var/log/apache2/"); |
||
| 109 | $this->addPath("/var/log/httpd/"); |
||
| 110 | $this->addPath("/usr/local/var/log/apache/"); |
||
| 111 | $this->addPath("/usr/local/var/log/apache2/"); |
||
| 112 | $this->addPath("/usr/local/var/log/httpd/"); |
||
| 113 | $this->addPath("/opt/local/apache/logs/"); |
||
| 114 | $this->addPath("/opt/local/apache2/logs/"); |
||
| 115 | $this->addPath("/opt/local/httpd/logs/"); |
||
| 116 | $this->addPath("C:/wamp/logs/"); |
||
| 117 | |||
| 118 | $this->addFile('error.log'); |
||
| 119 | $this->addFile('error_log'); |
||
| 120 | $this->addFile("apache_error.log"); |
||
| 121 | |||
| 122 | // *************** |
||
| 123 | // define patterns |
||
| 124 | // *************** |
||
| 125 | |||
| 126 | $this->addNamedPattern('%%' , 'percent', '\%'); |
||
| 127 | |||
| 128 | // %t The current time |
||
| 129 | // %{u}t The current time including micro-seconds |
||
| 130 | $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})\]'; |
||
| 131 | $this->addPattern('\[%{u}t\]', $datePattern); |
||
| 132 | $this->addPattern('\[%t\]', $datePattern); |
||
| 133 | $this->addPattern('%t', $datePattern); |
||
| 134 | |||
| 135 | // %a Client IP address and port of the request (port is not registered by parser). |
||
| 136 | // That column may be missing depending of error |
||
| 137 | $clientIpPattern = '( \[client (?P<remoteIp>' . self::PATTERN_IP_ALL . ')(:[\d]+|)?\])?'; |
||
| 138 | $this->addPattern(' \[client %a\]' , $clientIpPattern); |
||
| 139 | $this->addPattern(' \[%a\]' , $clientIpPattern); |
||
| 140 | $this->addPattern(' %a' , $clientIpPattern); |
||
| 141 | |||
| 142 | // %A Local IP-address and port |
||
| 143 | // That column may be missing depending of error |
||
| 144 | $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); |
||
| 145 | |||
| 146 | // %m Name of the module logging the message |
||
| 147 | // %l Loglevel of the message |
||
| 148 | $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 149 | $this->addPattern('\[%-m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); |
||
| 150 | $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); |
||
| 151 | $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); |
||
| 152 | |||
| 153 | // %P Process ID of current process (since apache 2.4?) |
||
| 154 | // %T Thread ID of current thread |
||
| 155 | $this->addPattern('\[pid %P:tid %T\]', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 156 | $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); |
||
| 157 | $this->addPattern('\[pid %P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 158 | $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]'); |
||
| 159 | $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); |
||
| 160 | |||
| 161 | // %E APR/OS error status code and string |
||
| 162 | // That column may be missing depending of error |
||
| 163 | // note we match errorCode only, let error string in %M (message) |
||
| 164 | $this->addPattern(' %E:', '( (?P<errorCode>[\w\d]+):)?'); |
||
| 165 | |||
| 166 | // %F Source file name and line number of the log call |
||
| 167 | $this->addPattern(' %F:', '( (?P<fileName>[^\*\s\|><\?]*[\/][^\*\s\|><\?]*):)?'); |
||
| 168 | |||
| 169 | // %M The actual log message |
||
| 170 | $this->addNamedPattern('%M', 'message', '.+?'); |
||
| 171 | |||
| 172 | // now let default constructor |
||
| 173 | parent::__construct($format, $factory); |
||
| 174 | } |
||
| 195 | } |