|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the browscap-php package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 1998-2017, Browser Capabilities Project |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types = 1); |
|
12
|
|
|
namespace BrowscapPHP\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Monolog\ErrorHandler; |
|
15
|
|
|
use Monolog\Handler\ErrorLogHandler; |
|
16
|
|
|
use Monolog\Handler\PsrHandler; |
|
17
|
|
|
use Monolog\Logger; |
|
18
|
|
|
use Monolog\Processor\MemoryPeakUsageProcessor; |
|
19
|
|
|
use Monolog\Processor\MemoryUsageProcessor; |
|
20
|
|
|
use Psr\Log\LoggerInterface; |
|
21
|
|
|
use Symfony\Component\Console\Logger\ConsoleLogger; |
|
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class LoggerHelper |
|
26
|
|
|
*/ |
|
27
|
|
|
final class LoggerHelper |
|
28
|
|
|
{ |
|
29
|
|
|
private function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* creates a \Monolog\Logger instance |
|
35
|
|
|
* |
|
36
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
37
|
|
|
* |
|
38
|
|
|
* @return LoggerInterface |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public static function createDefaultLogger(OutputInterface $output) : LoggerInterface |
|
41
|
|
|
{ |
|
42
|
1 |
|
$logger = new Logger('browscap'); |
|
43
|
1 |
|
$consoleLogger = new ConsoleLogger($output); |
|
44
|
1 |
|
$psrHandler = new PsrHandler($consoleLogger); |
|
45
|
|
|
|
|
46
|
1 |
|
$logger->pushHandler($psrHandler); |
|
47
|
1 |
|
$logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::NOTICE)); |
|
48
|
|
|
|
|
49
|
|
|
/** @var callable $memoryProcessor */ |
|
50
|
1 |
|
$memoryProcessor = new MemoryUsageProcessor(true); |
|
51
|
1 |
|
$logger->pushProcessor($memoryProcessor); |
|
52
|
|
|
|
|
53
|
|
|
/** @var callable $peakMemoryProcessor */ |
|
54
|
1 |
|
$peakMemoryProcessor = new MemoryPeakUsageProcessor(true); |
|
55
|
1 |
|
$logger->pushProcessor($peakMemoryProcessor); |
|
56
|
|
|
|
|
57
|
1 |
|
ErrorHandler::register($logger); |
|
58
|
|
|
|
|
59
|
1 |
|
return $logger; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|