1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace BrowscapPHP\Helper; |
5
|
|
|
|
6
|
|
|
use Monolog\ErrorHandler; |
7
|
|
|
use Monolog\Handler\ErrorLogHandler; |
8
|
|
|
use Monolog\Handler\PsrHandler; |
9
|
|
|
use Monolog\Logger; |
10
|
|
|
use Monolog\Processor\MemoryPeakUsageProcessor; |
11
|
|
|
use Monolog\Processor\MemoryUsageProcessor; |
12
|
|
|
use Psr\Log\LoggerInterface; |
13
|
|
|
use Symfony\Component\Console\Logger\ConsoleLogger; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class LoggerHelper |
18
|
|
|
*/ |
19
|
|
|
final class LoggerHelper |
20
|
|
|
{ |
21
|
|
|
private function __construct() |
22
|
|
|
{ |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* creates a \Monolog\Logger instance |
27
|
|
|
* |
28
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
29
|
|
|
* |
30
|
|
|
* @return LoggerInterface |
31
|
|
|
*/ |
32
|
1 |
|
public static function createDefaultLogger(OutputInterface $output) : LoggerInterface |
33
|
|
|
{ |
34
|
1 |
|
$logger = new Logger('browscap'); |
35
|
1 |
|
$consoleLogger = new ConsoleLogger($output); |
36
|
1 |
|
$psrHandler = new PsrHandler($consoleLogger); |
37
|
|
|
|
38
|
1 |
|
$logger->pushHandler($psrHandler); |
39
|
1 |
|
$logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::NOTICE)); |
40
|
|
|
|
41
|
|
|
/** @var callable $memoryProcessor */ |
42
|
1 |
|
$memoryProcessor = new MemoryUsageProcessor(true); |
43
|
1 |
|
$logger->pushProcessor($memoryProcessor); |
44
|
|
|
|
45
|
|
|
/** @var callable $peakMemoryProcessor */ |
46
|
1 |
|
$peakMemoryProcessor = new MemoryPeakUsageProcessor(true); |
47
|
1 |
|
$logger->pushProcessor($peakMemoryProcessor); |
48
|
|
|
|
49
|
1 |
|
ErrorHandler::register($logger); |
50
|
|
|
|
51
|
1 |
|
return $logger; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|