Passed
Push — master ( 48f77b...329461 )
by Timo
15:28
created

SolrLogManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
     * SolrLogManager constructor.
52
     *
53
     * @param $className
54
     */
55 246
    public function __construct($className)
56
    {
57 246
        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger($className);
58 246
    }
59
60
    /**
61
     * Adds an entry to the LogManager
62
     *
63
     * @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
64
     * @param string $message Log message.
65
     * @param array $data Additional data to log
66
     *
67
     * @return mixed
68
     */
69 53
    public function log($level, $message, array $data = [])
70
    {
71 53
        $this->logger->log($level, $message, $data);
72 53
    }
73
74
75
    /**
76
     * Check if Logging via debugOutput has been configured
77
     *
78
     * @return bool
79
     */
80
    public function isDebugOutputEnabled()
81
    {
82
        return Util::getSolrConfiguration()->getLoggingDebugOutput();
83
    }
84
}
85