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\Util; |
19
|
|
|
use TYPO3\CMS\Core\Http\ApplicationType; |
20
|
|
|
use TYPO3\CMS\Core\Utility\DebugUtility; |
21
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
22
|
|
|
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The DebugWriter is used to write the devLog messages to the output of the page, or to the TYPO3 console in the |
26
|
|
|
* backend to provide a simple and lightweigt debugging possibility. |
27
|
|
|
* |
28
|
|
|
* @author Timo Hund <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class DebugWriter |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* When the feature is enabled with: plugin.tx_solr.logging.debugOutput the log writer uses the extbase |
35
|
|
|
* debug functionality in the frontend, or the console in the backend to display the devlog messages. |
36
|
|
|
* |
37
|
|
|
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string. |
38
|
|
|
* @param string $message Log message. |
39
|
|
|
* @param array $data Additional data to log |
40
|
|
|
*/ |
41
|
|
|
public function write($level, $message, $data = []) |
42
|
|
|
{ |
43
|
|
|
$debugAllowedForIp = $this->getIsAllowedByDevIPMask(); |
44
|
|
|
if (!$debugAllowedForIp) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$isDebugOutputEnabled = $this->getIsDebugOutputEnabled(); |
49
|
|
|
if (!$isDebugOutputEnabled) { |
50
|
43 |
|
return; |
51
|
|
|
} |
52
|
43 |
|
|
53
|
43 |
|
$isPageIndexingRequest = $this->getIsPageIndexingRequest(); |
54
|
41 |
|
if ($isPageIndexingRequest) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
2 |
|
|
58
|
2 |
|
$this->writeDebugMessage($level, $message, $data); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
1 |
|
* @return bool |
63
|
1 |
|
*/ |
64
|
|
|
protected function getIsAllowedByDevIPMask() |
65
|
|
|
{ |
66
|
|
|
return GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']); |
|
|
|
|
67
|
|
|
} |
68
|
40 |
|
|
69
|
|
|
/** |
70
|
40 |
|
* Check if Logging via debugOutput has been configured |
71
|
|
|
* |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
protected function getIsDebugOutputEnabled() |
75
|
|
|
{ |
76
|
|
|
return Util::getSolrConfiguration()->getLoggingDebugOutput(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function getIsPageIndexingRequest(): bool |
80
|
|
|
{ |
81
|
|
|
if (!$GLOBALS['TYPO3_REQUEST'] instanceof Request) { |
|
|
|
|
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
return $GLOBALS['TYPO3_REQUEST']->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string. |
89
|
|
|
* @param string $message Log message. |
90
|
|
|
* @param array $data Additional data to log |
91
|
|
|
*/ |
92
|
|
|
protected function writeDebugMessage($level, $message, $data) |
93
|
|
|
{ |
94
|
|
|
$parameters = ['extKey' => 'solr', 'msg' => $message, 'level' => $level, 'data' => $data]; |
95
|
|
|
$message = isset($parameters['msg']) ? $parameters['msg'] : ''; |
96
|
|
|
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) { |
97
|
|
|
DebugUtility::debug($parameters, $parameters['extKey'], 'DevLog ext:solr: ' . $message); |
|
|
|
|
98
|
|
|
} else { |
99
|
|
|
echo $message . ':<br/>'; |
100
|
|
|
DebuggerUtility::var_dump($parameters); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|