Completed
Push — master ( 1235b0...90fadd )
by Tim
15s
created

LoggerFactory::createLoggers()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 17
cp 0
rs 8.8571
cc 2
eloc 12
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Logger\LoggerFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli\Logger;
22
23
use Monolog\Logger;
24
use Monolog\Handler\ErrorLogHandler;
25
use TechDivision\Import\Utils\LoggerKeys;
26
use TechDivision\Import\ConfigurationInterface;
27
28
/**
29
 * The logger factory implementation.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2016 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-cli-simple
35
 * @link      http://www.techdivision.com
36
 */
37
class LoggerFactory
38
{
39
40
    /**
41
     * Create's and return's the loggers to use.
42
     *
43
     * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration with the data to create the loggers with
44
     *
45
     * @return array The array with the initialized loggers
46
     */
47
    public static function createLoggers(ConfigurationInterface $configuration)
48
    {
49
50
        // initialize the array for the loggers
51
        $loggers = array();
52
53
        // initialize the default system logger
54
        $systemLogger = new Logger('techdivision/import');
55
        $systemLogger->pushHandler(
56
            new ErrorLogHandler(
57
                ErrorLogHandler::OPERATING_SYSTEM,
58
                $configuration->getLogLevel()
59
            )
60
        );
61
62
        // add it to the array
63
        $loggers[LoggerKeys::SYSTEM] = $systemLogger;
64
65
        // append the configured loggers or override the default one
66
        foreach ($configuration->getLoggers() as $loggerConfiguration) {
67
            // load the factory class that creates the logger instance
68
            $loggerFactory = $loggerConfiguration->getFactory();
69
            // create the logger instance and add it to the available loggers
70
            $loggers[$loggerConfiguration->getName()] = $loggerFactory::factory($configuration, $loggerConfiguration);
71
        }
72
73
        // return the array with the initialized loggers
74
        return $loggers;
75
    }
76
}
77