|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aoe\FeloginBruteforceProtection\Service\Logger; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2019 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* |
|
12
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
13
|
|
|
* free software; you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU General Public License as published by |
|
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
16
|
|
|
* (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* The GNU General Public License can be found at |
|
19
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
20
|
|
|
* |
|
21
|
|
|
* This script is distributed in the hope that it will be useful, |
|
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24
|
|
|
* GNU General Public License for more details. |
|
25
|
|
|
* |
|
26
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
27
|
|
|
***************************************************************/ |
|
28
|
|
|
|
|
29
|
|
|
use Aoe\FeloginBruteforceProtection\System\Configuration; |
|
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class Logger |
|
34
|
|
|
* @package Aoe\FeloginBruteforceProtection\Service\Logger |
|
35
|
|
|
*/ |
|
36
|
|
|
class Logger |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var LoggerInterface */ |
|
39
|
|
|
private $loggerImplementation; |
|
40
|
|
|
|
|
41
|
|
|
/** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface */ |
|
42
|
|
|
protected $objectManager; |
|
43
|
|
|
|
|
44
|
|
|
/** @var Configuration */ |
|
45
|
|
|
protected $configuration; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param LoggerInterface $loggerImplementation |
|
49
|
|
|
*/ |
|
50
|
|
|
public function injectLoggerImplementation(LoggerInterface $loggerImplementation) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->loggerImplementation = $loggerImplementation; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $message, The Message to log |
|
57
|
|
|
* @param int $severity type and severity of log entry |
|
58
|
|
|
* @param array|null $additionalData optional Array of additional data for the log entry which will be logged too |
|
59
|
|
|
* @param string|null $packageKey optional string with a free key for the application so the log entries are easier |
|
60
|
|
|
* to find |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
10 |
|
public function log( |
|
64
|
|
|
$message, |
|
65
|
|
|
$severity = LoggerInterface::SEVERITY_INFO, |
|
66
|
|
|
$additionalData = null, |
|
67
|
|
|
$packageKey = null |
|
68
|
|
|
) { |
|
69
|
10 |
|
if ($this->isLoggingEnabled() && $severity >= $this->getLogLevel()) { |
|
70
|
|
|
$this->getLoggerImplementation()->log($message, $severity, $additionalData, $packageKey); |
|
71
|
|
|
} |
|
72
|
10 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return bool |
|
76
|
|
|
*/ |
|
77
|
|
|
public function isLoggingEnabled() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getConfiguration()->isLoggingEnabled(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return int |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getLogLevel() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->getConfiguration()->getLogLevel(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return Configuration |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getConfiguration() |
|
94
|
|
|
{ |
|
95
|
|
|
if (!isset($this->configuration)) { |
|
96
|
|
|
$this->configuration = new Configuration(); |
|
97
|
|
|
} |
|
98
|
|
|
return $this->configuration; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return \TYPO3\CMS\Extbase\Object\ObjectManagerInterface |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getObjectManager() |
|
105
|
|
|
{ |
|
106
|
|
|
if (false === isset($this->objectManager)) { |
|
107
|
|
|
$this->objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
108
|
|
|
} |
|
109
|
|
|
return $this->objectManager; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return LoggerInterface |
|
114
|
|
|
*/ |
|
115
|
|
|
private function getLoggerImplementation() |
|
116
|
|
|
{ |
|
117
|
|
|
if (!is_object($this->loggerImplementation)) { |
|
118
|
|
|
/** @var LoggerInterface $loggerImplementation */ |
|
119
|
|
|
$loggerImplementation = $this->getObjectManager()->get( |
|
120
|
|
|
'Aoe\FeloginBruteforceProtection\Service\Logger\DevLogger' |
|
121
|
|
|
); |
|
122
|
|
|
$this->injectLoggerImplementation($loggerImplementation); |
|
123
|
|
|
} |
|
124
|
|
|
return $this->loggerImplementation; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|