/
Logger.php
43 lines (39 loc) · 1.24 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
<?php
namespace Concrete\Core\Permission;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Logging\Configuration\SimpleConfiguration;
use Concrete\Core\Logging\Entry\Permission\Assignment\Assignment;
use Concrete\Core\Logging\LoggerFactory;
use Monolog\Logger as Monolog;
class Logger
{
/**
* @var LoggerFactory
*/
protected $loggerFactory;
public function __construct(LoggerFactory $loggerFactory)
{
$this->loggerFactory = $loggerFactory;
}
public function shouldLogAssignment()
{
$configuration = $this->loggerFactory->getConfiguration();
if ($configuration instanceof SimpleConfiguration) {
$level = Monolog::toMonologLevel($configuration->getCoreLevel());
if ($level <= Monolog::INFO) {
// only log this if the level is set to info or lower.
return true;
} else {
return false;
}
}
return true;
}
public function log(Assignment $assignment)
{
if ($this->shouldLogAssignment()) {
$logger = $this->loggerFactory->createLogger(Channels::CHANNEL_PERMISSIONS);
$logger->info($assignment->getMessage(), $assignment->getContext());
}
}
}