-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.php
91 lines (79 loc) · 1.91 KB
/
Logger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* @copyright 2018 Alaa Al-Maliki <alaa.almaliki@gmail.com>
* @license MIT
*/
declare(strict_types=1);
namespace Alaa\Firephp;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\State;
use Monolog\Handler\FirePHPHandler;
use Monolog\LoggerFactory;
/**
* Class Logger
*
* @package Alaa\Firephp\Logger
* @author Alaa Al-Maliki <alaa.almaliki@gmail.com>
*/
class Logger
{
/**
* @var \Monolog\Logger
*/
protected $logger;
/**
* @var State
*/
protected $appState;
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;
/**
* Logger constructor.
*
* @param LoggerFactory $loggerFactory
* @param State $appState
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(LoggerFactory $loggerFactory, State $appState, ScopeConfigInterface $scopeConfig)
{
$this->logger = $loggerFactory->create(
['name' => 'FIREPHP', 'handlers' => [new FirePHPHandler()]]
);
$this->appState = $appState;
$this->scopeConfig = $scopeConfig;
}
/**
* @return \Monolog\Logger
*/
public function getLogger()
{
return $this->logger;
}
/**
* @param string $message
* @param array $context
*/
public function debug(string $message, array $context = [])
{
if (!$this->getConfigFlag('enabled')) {
return;
}
$canLog = true;
if ($this->appState->getMode() !== 'developer') {
$canLog &= $this->getConfigFlag('production_enabled');
}
if ($canLog) {
$this->getLogger()->debug($message, $context);
}
}
/**
* @param string $title
* @return bool
*/
protected function getConfigFlag(string $title): bool
{
return $this->scopeConfig->isSetFlag('firephp/settings/' . $title);
}
}