|
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
|
3 |
|
* |
|
28
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
29
|
3 |
|
* |
|
30
|
|
|
* @return LoggerInterface |
|
31
|
3 |
|
*/ |
|
32
|
1 |
|
public static function createDefaultLogger(OutputInterface $output) : LoggerInterface |
|
33
|
1 |
|
{ |
|
34
|
1 |
|
$logger = new Logger('browscap'); |
|
35
|
|
|
$consoleLogger = new ConsoleLogger($output); |
|
36
|
|
|
$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
|
2 |
|
/** @var callable $peakMemoryProcessor */ |
|
46
|
2 |
|
$peakMemoryProcessor = new MemoryPeakUsageProcessor(true); |
|
47
|
|
|
$logger->pushProcessor($peakMemoryProcessor); |
|
48
|
|
|
|
|
49
|
2 |
|
ErrorHandler::register($logger); |
|
50
|
2 |
|
|
|
51
|
|
|
return $logger; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|