|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ___ _ |
|
5
|
|
|
* | _ \ __ _ _ _ ___ ___ | | ___ __ _ |
|
6
|
|
|
* | _// _` || '_|(_-</ -_)| |/ _ \/ _` | |
|
7
|
|
|
* |_| \__,_||_| /__/\___||_|\___/\__, | |
|
8
|
|
|
* |___/ |
|
9
|
|
|
* |
|
10
|
|
|
* (c) Kristuff <[email protected]> |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
13
|
|
|
* file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* @version 0.2.0 |
|
16
|
|
|
* @copyright 2017-2020 Kristuff |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Kristuff\Parselog; |
|
20
|
|
|
|
|
21
|
|
|
use Kristuff\Parselog\Core\LogEntryFactoryInterface; |
|
22
|
|
|
use Kristuff\Parselog\Software\SoftwareLogParser; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
class LogParserFactory |
|
28
|
|
|
{ |
|
29
|
|
|
const TYPE_APACHE_ACCESS = 'apache_access'; |
|
30
|
|
|
const TYPE_APACHE_ERROR = 'apache_error'; |
|
31
|
|
|
const TYPE_SYSLOG = 'syslog'; |
|
32
|
|
|
const TYPE_FAIL2BAN = 'fail2ban'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gets a new LogParser instance based on given logType |
|
36
|
|
|
* |
|
37
|
|
|
* @access public |
|
38
|
|
|
* @static |
|
39
|
|
|
* @param string $logType The internal log type |
|
40
|
|
|
* @param string $format The log format. Default is null |
|
41
|
|
|
* @param LogEntryFactoryInterface $factory The custom log entry factory. Default is null (use default factory) |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Kristuff\Parselog\LogParser|null |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function getParser(string $logType, string $format = null, LogEntryFactoryInterface $factory = null): ?SoftwareLogParser |
|
46
|
|
|
{ |
|
47
|
|
|
switch ($logType){ |
|
48
|
|
|
|
|
49
|
|
|
case self::TYPE_APACHE_ACCESS: |
|
50
|
|
|
return new \Kristuff\Parselog\Software\ApacheAccessLogParser($format, $factory); |
|
51
|
|
|
|
|
52
|
|
|
case self::TYPE_APACHE_ERROR: |
|
53
|
|
|
return new \Kristuff\Parselog\Software\ApacheErrorLogParser($format, $factory); |
|
54
|
|
|
|
|
55
|
|
|
case self::TYPE_SYSLOG: |
|
56
|
|
|
return new \Kristuff\Parselog\Software\SyslogParser($format, $factory); |
|
57
|
|
|
|
|
58
|
|
|
case self::TYPE_FAIL2BAN: |
|
59
|
|
|
return new \Kristuff\Parselog\Software\Fail2BanLogParser($format, $factory); |
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
return null; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |