| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 | * @access protected | 
| 52 | 52 | * @var array | 
| 53 | 53 | */ | 
| 54 | - protected $patterns = []; | |
| 54 | + protected $patterns = [ ]; | |
| 55 | 55 | |
| 56 | 56 | /** | 
| 57 | 57 | * The time format | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 | public function addNamedPattern(string $placeholder, string $propertyName, string $pattern, bool $required = true): void | 
| 92 | 92 |      { | 
| 93 | 93 | // First field must be a required field | 
| 94 | -        if ($required === false && count($this->patterns) === 0){ | |
| 94 | +        if ($required === false && count($this->patterns) === 0) { | |
| 95 | 95 | throw new \Kristuff\Parselog\InvalidArgumentException( | 
| 96 | 96 | "Invalid value 'false' for argument 'required' given: First pattern must be a required pattern."); | 
| 97 | 97 | } | 
| @@ -100,8 +100,8 @@ discard block | ||
| 100 | 100 | // Adjust pattern for nullable columns and add space before placeholder | 
| 101 | 101 | // - $format = '%t %l %P %E: %a %M'; | 
| 102 | 102 | // + $format = '%t %l( %P)?( %E:)?(%a)? %M'; | 
| 103 | - $key = $required ? $placeholder : ' ' . $placeholder ; | |
| 104 | - $val = '(?P<'. $propertyName . '>' . ($required ? $pattern : '( ' . $pattern . ')?') . ')'; | |
| 103 | + $key = $required ? $placeholder : ' '.$placeholder; | |
| 104 | + $val = '(?P<'.$propertyName.'>'.($required ? $pattern : '( '.$pattern.')?').')'; | |
| 105 | 105 | |
| 106 | 106 | $this->addPattern($key, $val); | 
| 107 | 107 | } | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | */ | 
| 119 | 119 | public function addPattern(string $placeholder, string $pattern): void | 
| 120 | 120 |      { | 
| 121 | - $this->patterns[$placeholder] = $pattern; | |
| 121 | + $this->patterns[ $placeholder ] = $pattern; | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | /** | 
| @@ -148,7 +148,7 @@ discard block | ||
| 148 | 148 |          $format = str_replace("\\", '', $format); | 
| 149 | 149 | |
| 150 | 150 | // store log format update IP pattern | 
| 151 | - $this->logFormat = $format ; | |
| 151 | + $this->logFormat = $format; | |
| 152 | 152 | $this->updateIpPatterns(); | 
| 153 | 153 | |
| 154 | 154 | // strtr won't work for "complex" header patterns | 
| @@ -208,7 +208,7 @@ discard block | ||
| 208 | 208 | protected function getTimestamp($time): ?int | 
| 209 | 209 |      { | 
| 210 | 210 | // try to get stamp from string | 
| 211 | -        if (isset($this->timeFormat)){ | |
| 211 | +        if (isset($this->timeFormat)) { | |
| 212 | 212 | $dateTime = DateTime::createFromFormat($this->timeFormat, $time); | 
| 213 | 213 | |
| 214 | 214 |              if (false !== $dateTime) { | 
| @@ -236,11 +236,11 @@ discard block | ||
| 236 | 236 | // Set IPv4 & IPv6 recognition patterns | 
| 237 | 237 |          $ipPatterns = implode('|', [ | 
| 238 | 238 | 'ipv4' => self::PATTERN_IP_V4, | 
| 239 | - 'ipv6full' => self::PATTERN_IP_V6_FULL, // 1:1:1:1:1:1:1:1 | |
| 240 | - 'ipv6null' => self::PATTERN_IP_V6_NULL, // :: | |
| 241 | - 'ipv6leading' => self::PATTERN_IP_V6_LEADING, // ::1:1:1:1:1:1:1 | |
| 242 | - 'ipv6mid' => self::PATTERN_IP_V6_MID, // 1:1:1::1:1:1 | |
| 243 | - 'ipv6trailing' => self::PATTERN_IP_V6_TRAILING, // 1:1:1:1:1:1:1:: | |
| 239 | + 'ipv6full' => self::PATTERN_IP_V6_FULL, // 1:1:1:1:1:1:1:1 | |
| 240 | + 'ipv6null' => self::PATTERN_IP_V6_NULL, // :: | |
| 241 | + 'ipv6leading' => self::PATTERN_IP_V6_LEADING, // ::1:1:1:1:1:1:1 | |
| 242 | + 'ipv6mid' => self::PATTERN_IP_V6_MID, // 1:1:1::1:1:1 | |
| 243 | + 'ipv6trailing' => self::PATTERN_IP_V6_TRAILING, // 1:1:1:1:1:1:1:: | |
| 244 | 244 | ]); | 
| 245 | 245 | |
| 246 | 246 |          foreach ($this->patterns as &$value) { | 
| @@ -154,23 +154,23 @@ discard block | ||
| 154 | 154 | // set 2.2 format by default. Will be changed to 2.4 format, ie: | 
| 155 | 155 | // $this->timeFormat = 'D M d H:i:s.u Y'; | 
| 156 | 156 |          // , if the format contain %{u} insted of %t   | 
| 157 | - $this->timeFormat = 'D M d H:i:s Y'; | |
| 157 | + $this->timeFormat = 'D M d H:i:s Y'; | |
| 158 | 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);   | |
| 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 | 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);   | |
| 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 | 174 | |
| 175 | 175 |          $this->addPath("/var/log/"); | 
| 176 | 176 |          $this->addPath("/var/log/apache/"); | 
| @@ -192,7 +192,7 @@ discard block | ||
| 192 | 192 | // define patterns | 
| 193 | 193 | // *************** | 
| 194 | 194 | |
| 195 | -        $this->addNamedPattern('%%' , 'percent', '\%'); | |
| 195 | +        $this->addNamedPattern('%%', 'percent', '\%'); | |
| 196 | 196 | |
| 197 | 197 | // %t The current time | 
| 198 | 198 |          // %{u}t 	The current time including micro-seconds | 
| @@ -203,29 +203,29 @@ discard block | ||
| 203 | 203 | |
| 204 | 204 | // %a Client IP address and port of the request (port is not registered by parser). | 
| 205 | 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); | |
| 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 | 210 | |
| 211 | 211 | // %A Local IP-address and port | 
| 212 | 212 | // That column may be missing depending of error | 
| 213 | -        $this->addNamedPattern('%A',  'localIP', self::PATTERN_IP_ALL, false); | |
| 213 | +        $this->addNamedPattern('%A', 'localIP', self::PATTERN_IP_ALL, false); | |
| 214 | 214 | |
| 215 | 215 | // %m Name of the module logging the message | 
| 216 | 216 | // %l Loglevel of the message | 
| 217 | -        $this->addPattern('\[%m:%l\]',  '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); | |
| 217 | +        $this->addPattern('\[%m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); | |
| 218 | 218 |          $this->addPattern('\[%-m:%l\]', '\[(?<module>.+?)?:(?P<level>[\w]+)\]'); | 
| 219 | -        $this->addPattern('\[%l\]',     '\[(?P<level>[\w:]+)\]'); | |
| 220 | -        $this->addPattern('%l',         '\[(?P<level>[\w:]+)\]'); | |
| 219 | +        $this->addPattern('\[%l\]', '\[(?P<level>[\w:]+)\]'); | |
| 220 | +        $this->addPattern('%l', '\[(?P<level>[\w:]+)\]'); | |
| 221 | 221 | |
| 222 | 222 | // %P Process ID of current process (since apache 2.4?) | 
| 223 | 223 | // %T Thread ID of current thread | 
| 224 | 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+)\]'); | |
| 225 | +        $this->addPattern('%P %T', '\[pid (?P<pid>\d+):tid (?P<tid>\d+)\]'); | |
| 226 | 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+)\]'); | |
| 227 | +        $this->addPattern('\[%P\]', '\[pid (?P<pid>\d+)\]');    | |
| 228 | +        $this->addPattern('%P', '\[pid (?P<pid>\d+)\]'); | |
| 229 | 229 | |
| 230 | 230 | // %E APR/OS error status code and string | 
| 231 | 231 | // That column may be missing depending of error | 
| @@ -236,11 +236,11 @@ discard block | ||
| 236 | 236 |          $this->addPattern(' %F:', '( (?P<fileName>[^ ]+\([\d]+\)):)?');               | 
| 237 | 237 | |
| 238 | 238 | // %M The actual log message | 
| 239 | -        $this->addNamedPattern('%M',  'message', '.+?'); | |
| 239 | +        $this->addNamedPattern('%M', 'message', '.+?'); | |
| 240 | 240 | |
| 241 | 241 | // referer (may be empty) | 
| 242 | -        $this->addPattern(' , referer %{Referer}i',   '(, referer: (?P<referer>[^ ]+))?'); | |
| 243 | -        $this->addPattern(', referer %{Referer}i',    '(, referer: (?P<referer>[^ ]+))?'); | |
| 242 | +        $this->addPattern(' , referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); | |
| 243 | +        $this->addPattern(', referer %{Referer}i', '(, referer: (?P<referer>[^ ]+))?'); | |
| 244 | 244 | |
| 245 | 245 | // now let default constructor | 
| 246 | 246 | parent::__construct($format, $factory); | 
| @@ -259,7 +259,7 @@ discard block | ||
| 259 | 259 | parent::setFormat($format); | 
| 260 | 260 | |
| 261 | 261 | // set the correct time format | 
| 262 | -        if (strpos($this->logFormat, '%{u}t') !== false){ | |
| 262 | +        if (strpos($this->logFormat, '%{u}t') !== false) { | |
| 263 | 263 | $this->timeFormat = 'D M d H:i:s.u Y'; | 
| 264 | 264 | } | 
| 265 | 265 | } |