Passed
Pull Request — master (#1091)
by Timo
15:55
created

SolrLogManager::isDebugOutputEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\System\Logging;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2017 - Thomas Hohn <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\Util;
29
use TYPO3\CMS\Core\Log\LogLevel;
30
use TYPO3\CMS\Core\Log\LogManager;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33
/**
34
 * Wrapper to for the TYPO3 Logging Framework
35
 *
36
 * @author Thomas Hohn <[email protected]>
37
 */
38
class SolrLogManager
39
{
40
    const WARNING = LogLevel::WARNING;
41
    const ERROR = LogLevel::ERROR;
42
    const INFO = LogLevel::INFO;
43
    const NOTICE = LogLevel::NOTICE;
44
45
    /**
46
     * @var \TYPO3\CMS\Core\Log\Logger
47
     */
48
    protected $logger = null;
49
50
    /**
51
     * @var DebugWriter
52
     */
53
    protected $debugWriter = null;
54
55
    /**
56
     * SolrLogManager constructor.
57
     *
58
     * @param $className
59
     * @param DebugWriter $debugWriter
60
     */
61 246
    public function __construct($className, DebugWriter $debugWriter = null)
62
    {
63 246
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger($className);
64 246
        $this->debugWriter = isset($debugWriter) ? $debugWriter : GeneralUtility::makeInstance(DebugWriter::class);
65 246
    }
66
67
    /**
68
     * Adds an entry to the LogManager
69
     *
70
     * @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
71
     * @param string $message Log message.
72
     * @param array $data Additional data to log
73
     *
74
     * @return mixed
75
     */
76 53
    public function log($level, $message, array $data = [])
77
    {
78 53
        $this->logger->log($level, $message, $data);
79 53
        $this->debugWriter->write($level, $message, $data);
80 53
    }
81
}
82