<?php
use Psr\Container\ContainerInterface;

return [
    Monolog\Formatter\LineFormatter::class => function(ContainerInterface $container) {
        return (new Monolog\Formatter\LineFormatter(null, null, false, false, true))
            ->setBasePath('/code/');
    },
    Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
        return new Monolog\Logger('incoviba', [
            new Monolog\Handler\FilterHandler(
                ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
                ? (new Monolog\Handler\StreamHandler('/logs/error.log'))
                    ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
                : (new Monolog\Handler\RotatingFileHandler('/logs/error.log', 10))
                    ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class)),
                Monolog\Level::Error,
                Monolog\Level::Error
            ),
            new Monolog\Handler\FilterHandler(
                ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
                ? (new Monolog\Handler\StreamHandler('/logs/critical.log'))
                    ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
                : (new Monolog\Handler\RotatingFileHandler('/logs/critical.log', 10))
                    ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class)),
                Monolog\Level::Critical
            ),
            new Monolog\Handler\FilterHandler(
                ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
                    ? (new Monolog\Handler\StreamHandler('/logs/debug.log'))
                        ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
                    : new Monolog\Handler\RedisHandler($container->get(Predis\ClientInterface::class), 'logs:notices'),
                Monolog\Level::Debug,
                Monolog\Level::Info
            ),
            new Monolog\Handler\FilterHandler(
                ($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
                    ? (new Monolog\Handler\StreamHandler('/logs/notices.log'))
                        ->setFormatter($container->get(Monolog\Formatter\LineFormatter::class))
                    : (new Incoviba\Common\Implement\Log\MySQLHandler($container->get(Incoviba\Common\Define\Connection::class)))
                        ->setFormatter(new Incoviba\Common\Implement\Log\PDOFormatter()),
                Monolog\Level::Notice,
                Monolog\Level::Warning
            )
        ], [
            $container->get(Incoviba\Common\Implement\Log\UserProcessor::class),
            $container->get(Monolog\Processor\IntrospectionProcessor::class),
            $container->get(Monolog\Processor\WebProcessor::class),
            $container->get(Monolog\Processor\MemoryUsageProcessor::class),
            $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class),
            $container->get(Monolog\Processor\PsrLogMessageProcessor::class),
        ]);
    },
    'loginLogger' => function(ContainerInterface $container) {
        return new Monolog\Logger('login', [
            new Monolog\Handler\RedisHandler($container->get(Predis\ClientInterface::class), 'logs:login'),
        ], [
            $container->get(Monolog\Processor\IntrospectionProcessor::class),
            $container->get(Monolog\Processor\WebProcessor::class),
            $container->get(Monolog\Processor\MemoryUsageProcessor::class),
            $container->get(Monolog\Processor\MemoryPeakUsageProcessor::class),
            $container->get(Monolog\Processor\PsrLogMessageProcessor::class),
        ]);
    }
];
