src/Utils/LoggerFactory.php
/**
     * Creates a new logger instance based on the passed logger configuration.
     *
     * @param \TechDivision\Import\Configuration\ConfigurationInterface       $configuration       The system configuration
     * @param \TechDivision\Import\Configuration\LoggerConfigurationInterface $loggerConfiguration The logger configuration
     *
     * @return \Psr\Log\LoggerInterface The logger instance
     */
Creates a new logger instance based on the passed logger configuration.

@return \Psr\Log\LoggerInterface The logger instance
Creates a new logger instance based on the passed logger configuration . @return \ Psr \ Log \ LoggerInterface The logger instance
public static function factory(
        ConfigurationInterface $configuration,
        LoggerConfigurationInterface $loggerConfiguration
    ) {
        $availableProcessors = $loggerConfiguration->getProcessors();
        $processors = array();
        foreach ($availableProcessors as $processorConfiguration) {
            $reflectionClass = new \ReflectionClass($processorConfiguration->getType());
            $processors[] = $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $processorConfiguration->getParams()));
        }
        $availableHandlers = $loggerConfiguration->getHandlers();
        $handlers = array();
        foreach ($availableHandlers as $handlerConfiguration) {
            if ($swiftMailerConfiguration = $handlerConfiguration->getSwiftMailer()) {
                $factory = $swiftMailerConfiguration->getFactory();
                $swiftMailer = $factory::factory($swiftMailerConfiguration);
                $bubble = $handlerConfiguration->getParam(LoggerKeys::BUBBLE);
                $logLevel = $handlerConfiguration->getParam(LoggerKeys::LOG_LEVEL);
                $to = $swiftMailerConfiguration->getParam(SwiftMailerKeys::TO);
                $from = $swiftMailerConfiguration->getParam(SwiftMailerKeys::FROM);
                $subject = $swiftMailerConfiguration->getParam(SwiftMailerKeys::SUBJECT);
                $contentType = $swiftMailerConfiguration->getParam(SwiftMailerKeys::CONTENT_TYPE);
                $message = $swiftMailer->createMessage()
                    ->setSubject(sprintf('[%s] %s', $configuration->getSystemName(), $subject))
                    ->setFrom($from)
                    ->setTo($to)
                    ->setBody('', $contentType);
                $reflectionClass = new \ReflectionClass($handlerConfiguration->getType());
                $handler = $reflectionClass->newInstanceArgs(array($swiftMailer, $message, $logLevel, $bubble));
            } else {
                $reflectionClass = new \ReflectionClass($handlerConfiguration->getType());
                $params = $handlerConfiguration->getParams();
                if (!isset($params[ConfigurationKeys::LEVEL])) {
                    $params[ConfigurationKeys::LEVEL] = $configuration->getLogLevel();
                }
                $handler = $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $params));
            }
            if ($formatterConfiguration = $handlerConfiguration->getFormatter()) {
                $reflectionClass = new \ReflectionClass($formatterConfiguration->getType());
                $handler->setFormatter($reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $formatterConfiguration->getParams())));
            }
            $handlers[] = $handler;
        }
        $loggerParams = array(
            ConfigurationKeys::NAME       => $loggerConfiguration->getChannelName(),
            ConfigurationKeys::HANDLERS   => $handlers,
            ConfigurationKeys::PROCESSORS => $processors
        );
        $loggerParams = array_merge($loggerParams, $loggerConfiguration->getParams());
        $reflectionClass = new \ReflectionClass($loggerConfiguration->getType());
        return $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $loggerParams));
    }
public static function factory ( ConfigurationInterface $ configuration , LoggerConfigurationInterface $ loggerConfiguration ) { $ availableProcessors = $ loggerConfiguration -> getProcessors ( ) ; $ processors = array ( ) ; foreach ( $ availableProcessors as $ processorConfiguration ) { $ reflectionClass = new \ ReflectionClass ( $ processorConfiguration -> getType ( ) ) ; $ processors [ ] = $ reflectionClass -> newInstanceArgs ( ConfigurationUtil :: prepareConstructorArgs ( $ reflectionClass , $ processorConfiguration -> getParams ( ) ) ) ; } $ availableHandlers = $ loggerConfiguration -> getHandlers ( ) ; $ handlers = array ( ) ; foreach ( $ availableHandlers as $ handlerConfiguration ) { if ( $ swiftMailerConfiguration = $ handlerConfiguration -> getSwiftMailer ( ) ) { $ factory = $ swiftMailerConfiguration -> getFactory ( ) ; $ swiftMailer = $ factory :: factory ( $ swiftMailerConfiguration ) ; $ bubble = $ handlerConfiguration -> getParam ( LoggerKeys :: BUBBLE ) ; $ logLevel = $ handlerConfiguration -> getParam ( LoggerKeys :: LOG_LEVEL ) ; $ to = $ swiftMailerConfiguration -> getParam ( SwiftMailerKeys :: TO ) ; $ from = $ swiftMailerConfiguration -> getParam ( SwiftMailerKeys :: FROM ) ; $ subject = $ swiftMailerConfiguration -> getParam ( SwiftMailerKeys :: SUBJECT ) ; $ contentType = $ swiftMailerConfiguration -> getParam ( SwiftMailerKeys :: CONTENT_TYPE ) ; $ message = $ swiftMailer -> createMessage ( ) -> setSubject ( sprintf ( '[%s] %s' , $ configuration -> getSystemName ( ) , $ subject ) ) -> setFrom ( $ from ) -> setTo ( $ to ) -> setBody ( '' , $ contentType ) ; $ reflectionClass = new \ ReflectionClass ( $ handlerConfiguration -> getType ( ) ) ; $ handler = $ reflectionClass -> newInstanceArgs ( array ( $ swiftMailer , $ message , $ logLevel , $ bubble ) ) ; } else { $ reflectionClass = new \ ReflectionClass ( $ handlerConfiguration -> getType ( ) ) ; $ params = $ handlerConfiguration -> getParams ( ) ; if ( ! isset ( $ params [ ConfigurationKeys :: LEVEL ] ) ) { $ params [ ConfigurationKeys :: LEVEL ] = $ configuration -> getLogLevel ( ) ; } $ handler = $ reflectionClass -> newInstanceArgs ( ConfigurationUtil :: prepareConstructorArgs ( $ reflectionClass , $ params ) ) ; } if ( $ formatterConfiguration = $ handlerConfiguration -> getFormatter ( ) ) { $ reflectionClass = new \ ReflectionClass ( $ formatterConfiguration -> getType ( ) ) ; $ handler -> setFormatter ( $ reflectionClass -> newInstanceArgs ( ConfigurationUtil :: prepareConstructorArgs ( $ reflectionClass , $ formatterConfiguration -> getParams ( ) ) ) ) ; } $ handlers [ ] = $ handler ; } $ loggerParams = array ( ConfigurationKeys :: NAME => $ loggerConfiguration -> getChannelName ( ) , ConfigurationKeys :: HANDLERS => $ handlers , ConfigurationKeys :: PROCESSORS => $ processors ) ; $ loggerParams = array_merge ( $ loggerParams , $ loggerConfiguration -> getParams ( ) ) ; $ reflectionClass = new \ ReflectionClass ( $ loggerConfiguration -> getType ( ) ) ; return $ reflectionClass -> newInstanceArgs ( ConfigurationUtil :: prepareConstructorArgs ( $ reflectionClass , $ loggerParams ) ) ; }
Creates a new logger instance based on the passed logger configuration.
Creates a new logger instance based on the passed logger configuration .
// load the available processors from the configuration // initialize the processors /** @var \TechDivision\Import\Configuration\Logger\ProcessorConfigurationInterface $processorConfiguration */ // load the available handlers from the configuration // initialize the handlers /** @var \TechDivision\Import\Configuration\Logger\HandlerConfigurationInterface $handlerConfiguration */ // query whether or not, we've a swift mailer configuration // load the factory that creates the swift mailer instance // create the swift mailer instance // load the generic logger configuration // load sender/receiver configuration // initialize the message template // initialize the handler node // initialize the handler node // load the params // set the default log level, if not already set explicitly // create the handler instance // if we've a formatter, initialize the formatter also // add the handler // prepare the logger params // append the params from the logger configuration // initialize the logger instance itself