Completed
Push — feature/modernize-a-bit ( fefe78...b3f976 )
by Narcotic
04:59
created

LoggerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 43
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 31 2
1
<?php
2
/**
3
 * small factory to get a logger class
4
 */
5
6
namespace Graviton\ImportExport\Util;
7
8
use Monolog\Formatter\LineFormatter;
9
use Monolog\Handler\RavenHandler;
10
use Monolog\Handler\StreamHandler;
11
use Monolog\Logger;
12
use Raven_Client;
13
use Raven_ErrorHandler;
14
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * @author   List of contributors <https://github.com/libgraviton/import-export/graphs/contributors>
19
 * @license  https://opensource.org/licenses/MIT MIT License
20
 * @link     http://swisscom.ch
21
 */
22
class LoggerFactory
23
{
24
25
    /**
26
     * gets a logger instance
27
     *
28
     * @param OutputInterface|null $output output interface
29
     *
30
     * @return Logger a logger
31
     * @throws \Exception
32
     */
33 6
    public static function getInstance(OutputInterface $output = null)
34
    {
35 6
        $sentryClient = new Raven_Client(
36 6
            null,
37
            [
38 6
                'app_path' => __DIR__.'/../../',
39
                'tags' => ['application' => 'import-export']
40
            ]
41
        );
42
43 6
        $monologFormatter = new LineFormatter(null, 'Y-m-d H:i:sO');
44
45 6
        if ($output instanceof OutputInterface) {
46 6
            $mainHandler = new ConsoleHandler($output, Logger::INFO);
47
        } else {
48
            $mainHandler = new StreamHandler('php://stdout', Logger::INFO);
49
        }
50
51 6
        $mainHandler->setFormatter($monologFormatter);
52
53 6
        $logger = new Logger('app');
54 6
        $logger->pushHandler($mainHandler);
55 6
        $logger->pushHandler(new RavenHandler($sentryClient, Logger::WARNING));
56
57 6
        $errorHandler = new Raven_ErrorHandler($sentryClient);
58 6
        $errorHandler->registerExceptionHandler();
59 6
        $errorHandler->registerErrorHandler();
60 6
        $errorHandler->registerShutdownFunction();
61
62 6
        return $logger;
63
    }
64
}
65