<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of the Valkyrja Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Valkyrja\Log\Providers;

use Exception;
use Monolog\Handler\StreamHandler;
use Monolog\Logger as Monolog;
use Psr\Log\LoggerInterface;
use Valkyrja\Container\Container;
use Valkyrja\Container\Support\Provider;
use Valkyrja\Log\Adapters\NullAdapter;
use Valkyrja\Log\Adapters\PsrAdapter;
use Valkyrja\Log\Constants\LogLevel;
use Valkyrja\Log\Drivers\Driver;
use Valkyrja\Log\Logger;

use function date;

/**
 * Class ServiceProvider.
 *
 * @author <NAME>
 */
class ServiceProvider extends Provider
{
    /**
     * The items provided by this provider.
     *
     * @return string[]
     */
    public static function publishers(): array
    {
        return [
            Logger::class          => 'publishLogger',
            Driver::class          => 'publishDefaultDriver',
            NullAdapter::class     => 'publishNullAdapter',
            PsrAdapter::class      => 'publishPsrAdapter',
            LoggerInterface::class => 'publishLoggerInterface',
        ];
    }

    /**
     * The items provided by this provider.
     *
     * @return array
     */
    public static function provides(): array
    {
        return [
            Logger::class,
            Driver::class,
            NullAdapter::class,
            PsrAdapter::class,
            LoggerInterface::class,
        ];
    }

    /**
     * Publish the provider.
     *
     * @param Container $container The container
     *
     * @throws Exception
     *
     * @return void
     */
    public static function publish(Container $container): void
    {
    }

    /**
     * Bind the logger service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishLogger(Container $container): void
    {
        $config = $container->getSingleton('config');

        $container->setSingleton(
            Logger::class,
            new \Valkyrja\Log\Managers\Logger(
                $container,
                $config['log']
            )
        );
    }

    /**
     * Publish the default driver service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishDefaultDriver(Container $container): void
    {
        $container->setClosure(
            Driver::class,
            static function (array $config, string $adapter) use ($container): Driver {
                return new Driver(
                    $container->get(
                        $adapter,
                        [
                            $config,
                        ]
                    )
                );
            }
        );
    }

    /**
     * Bind the psr adapter service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishPsrAdapter(Container $container): void
    {
        $container->setClosure(
            PsrAdapter::class,
            static function (array $config) use ($container): PsrAdapter {
                return new PsrAdapter(
                    $container->get(
                        LoggerInterface::class,
                        [
                            $config,
                        ]
                    ),
                    $config
                );
            }
        );
    }

    /**
     * Bind the null adapter service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishNullAdapter(Container $container): void
    {
        $container->setClosure(
            NullAdapter::class,
            static function (array $config): NullAdapter {
                return new NullAdapter(
                    $config
                );
            }
        );
    }

    /**
     * Bind the logger interface.
     *
     * @param Container $container The container
     *
     * @throws Exception
     *
     * @return void
     */
    public static function publishLoggerInterface(Container $container): void
    {
        $container->setClosure(
            LoggerInterface::class,
            static function (array $config): LoggerInterface {
                $filePath = $config['filePath'];
                $name     = $config['name'] . date('-Y-m-d');

                return new Monolog(
                    $name,
                    [
                        new StreamHandler(
                            "${filePath}/${name}.log",
                            LogLevel::DEBUG
                        ),
                    ]
                );
            }
        );
    }
}<commit_msg>Updating logging to allow for line breaks.<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of the Valkyrja Framework package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Valkyrja\Log\Providers;

use Exception;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger as Monolog;
use Psr\Log\LoggerInterface;
use Valkyrja\Container\Container;
use Valkyrja\Container\Support\Provider;
use Valkyrja\Log\Adapters\NullAdapter;
use Valkyrja\Log\Adapters\PsrAdapter;
use Valkyrja\Log\Constants\LogLevel;
use Valkyrja\Log\Drivers\Driver;
use Valkyrja\Log\Logger;

use function date;

/**
 * Class ServiceProvider.
 *
 * @author <NAME>
 */
class ServiceProvider extends Provider
{
    /**
     * The items provided by this provider.
     *
     * @return string[]
     */
    public static function publishers(): array
    {
        return [
            Logger::class          => 'publishLogger',
            Driver::class          => 'publishDefaultDriver',
            NullAdapter::class     => 'publishNullAdapter',
            PsrAdapter::class      => 'publishPsrAdapter',
            LoggerInterface::class => 'publishLoggerInterface',
        ];
    }

    /**
     * The items provided by this provider.
     *
     * @return array
     */
    public static function provides(): array
    {
        return [
            Logger::class,
            Driver::class,
            NullAdapter::class,
            PsrAdapter::class,
            LoggerInterface::class,
        ];
    }

    /**
     * Publish the provider.
     *
     * @param Container $container The container
     *
     * @throws Exception
     *
     * @return void
     */
    public static function publish(Container $container): void
    {
    }

    /**
     * Bind the logger service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishLogger(Container $container): void
    {
        $config = $container->getSingleton('config');

        $container->setSingleton(
            Logger::class,
            new \Valkyrja\Log\Managers\Logger(
                $container,
                $config['log']
            )
        );
    }

    /**
     * Publish the default driver service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishDefaultDriver(Container $container): void
    {
        $container->setClosure(
            Driver::class,
            static function (array $config, string $adapter) use ($container): Driver {
                return new Driver(
                    $container->get(
                        $adapter,
                        [
                            $config,
                        ]
                    )
                );
            }
        );
    }

    /**
     * Bind the psr adapter service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishPsrAdapter(Container $container): void
    {
        $container->setClosure(
            PsrAdapter::class,
            static function (array $config) use ($container): PsrAdapter {
                return new PsrAdapter(
                    $container->get(
                        LoggerInterface::class,
                        [
                            $config,
                        ]
                    ),
                    $config
                );
            }
        );
    }

    /**
     * Bind the null adapter service.
     *
     * @param Container $container The container
     *
     * @return void
     */
    public static function publishNullAdapter(Container $container): void
    {
        $container->setClosure(
            NullAdapter::class,
            static function (array $config): NullAdapter {
                return new NullAdapter(
                    $config
                );
            }
        );
    }

    /**
     * Bind the logger interface.
     *
     * @param Container $container The container
     *
     * @throws Exception
     *
     * @return void
     */
    public static function publishLoggerInterface(Container $container): void
    {
        $container->setClosure(
            LoggerInterface::class,
            static function (array $config): LoggerInterface {
                $filePath = $config['filePath'];
                $name     = $config['name'] . date('-Y-m-d');
                $handler  = new StreamHandler(
                    "${filePath}/${name}.log",
                    LogLevel::DEBUG
                );
                $formatter = new LineFormatter(
                    null,
                    null,
                    true,
                    true
                );

                $handler->setFormatter($formatter);

                return new Monolog(
                    $name,
                    [
                        $handler,
                    ]
                );
            }
        );
    }
}
{'fraction_non_alphanumeric': 0.09754399920453416, 'fraction_numerical': 0.00019886646117132345, 'mean_word_length': 1.4073719483006224, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7651455', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2456, 'n_words': 604}