|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace ApacheSolrForTypo3\Solr\System\Logging; |
|
17
|
|
|
|
|
18
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest; |
|
19
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
20
|
|
|
use TYPO3\CMS\Core\Http\ApplicationType; |
|
21
|
|
|
use TYPO3\CMS\Core\Http\Request; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\DebugUtility; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The DebugWriter is used to write the devLog messages to the output of the page, or to the TYPO3 console in the |
|
28
|
|
|
* backend to provide a simple and lightweight debugging possibility. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Timo Hund <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class DebugWriter |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* When the feature is enabled with: plugin.tx_solr.logging.debugOutput the log writer uses the extbase |
|
37
|
|
|
* debug functionality in the frontend, or the console in the backend to display the devlog messages. |
|
38
|
|
|
* |
|
39
|
|
|
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string. |
|
40
|
|
|
* @param string $message Log message. |
|
41
|
|
|
* @param array $data Additional data to log |
|
42
|
|
|
*/ |
|
43
|
|
|
public function write($level, $message, $data = []) |
|
44
|
|
|
{ |
|
45
|
|
|
$debugAllowedForIp = $this->getIsAllowedByDevIPMask(); |
|
46
|
|
|
if (!$debugAllowedForIp) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
43 |
|
$isDebugOutputEnabled = $this->getIsDebugOutputEnabled(); |
|
51
|
|
|
if (!$isDebugOutputEnabled) { |
|
52
|
43 |
|
return; |
|
53
|
43 |
|
} |
|
54
|
41 |
|
|
|
55
|
|
|
$isPageIndexingRequest = $this->getIsPageIndexingRequest(); |
|
56
|
|
|
if ($isPageIndexingRequest) { |
|
57
|
2 |
|
return; |
|
58
|
2 |
|
} |
|
59
|
1 |
|
|
|
60
|
|
|
$this->writeDebugMessage($level, $message, $data); |
|
61
|
|
|
} |
|
62
|
1 |
|
|
|
63
|
1 |
|
/** |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getIsAllowedByDevIPMask() |
|
67
|
|
|
{ |
|
68
|
40 |
|
return GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
40 |
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Check if Logging via debugOutput has been configured |
|
73
|
|
|
* |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getIsDebugOutputEnabled() |
|
77
|
|
|
{ |
|
78
|
|
|
return Util::getSolrConfiguration()->getLoggingDebugOutput(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
protected function getIsPageIndexingRequest(): bool |
|
82
|
|
|
{ |
|
83
|
|
|
if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof Request) { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
return $GLOBALS['TYPO3_REQUEST']->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string. |
|
91
|
|
|
* @param string $message Log message. |
|
92
|
|
|
* @param array $data Additional data to log |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function writeDebugMessage($level, $message, $data) |
|
95
|
|
|
{ |
|
96
|
|
|
$parameters = ['extKey' => 'solr', 'msg' => $message, 'level' => $level, 'data' => $data]; |
|
97
|
|
|
$message = $parameters['msg'] ?? ''; |
|
98
|
|
|
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) { |
|
99
|
|
|
DebugUtility::debug($parameters, $parameters['extKey'], 'DevLog ext:solr: ' . $message); |
|
|
|
|
|
|
100
|
|
|
} else { |
|
101
|
|
|
echo $message . ':<br/>'; |
|
102
|
|
|
DebuggerUtility::var_dump($parameters); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|