shlink/config/autoload/logger.global.php

77 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2019-10-05 10:26:10 -05:00
2017-10-12 03:13:20 -05:00
declare(strict_types=1);
namespace Shlinkio\Shlink;
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use Laminas\ServiceManager\Factory\InvokableFactory;
2022-06-04 01:59:17 -05:00
use Monolog\Level;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
2022-06-04 01:59:17 -05:00
use Shlinkio\Shlink\Common\Logger\LoggerFactory;
use Shlinkio\Shlink\Common\Logger\LoggerType;
use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware;
use Shlinkio\Shlink\Common\Middleware\RequestIdMiddleware;
2024-10-23 03:53:09 -05:00
use Shlinkio\Shlink\Core\Config\EnvVars;
use Shlinkio\Shlink\Core\EventDispatcher\Helper\RequestIdProvider;
use Shlinkio\Shlink\EventDispatcher\Util\RequestIdProviderInterface;
2024-10-23 03:53:09 -05:00
use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Config\runningInRoadRunner;
return (static function (): array {
2024-10-23 03:53:09 -05:00
$isDev = EnvVars::isDevEnv();
$common = [
2024-10-23 03:53:09 -05:00
'level' => $isDev ? Level::Debug->value : Level::Info->value,
'processors' => [RequestIdMiddleware::class],
'line_format' =>
'[%datetime%] [%extra.' . RequestIdMiddleware::ATTRIBUTE . '%] %channel%.%level_name% - %message%',
];
2024-10-23 03:53:09 -05:00
// In dev env or the docker container, stream Shlink logs to stderr, otherwise send them to a file
$useStreamForShlinkLogger = $isDev || env('SHLINK_RUNTIME') !== null;
return [
'logger' => [
2024-10-23 03:53:09 -05:00
'Shlink' => $useStreamForShlinkLogger ? [
'type' => LoggerType::STREAM->value,
'destination' => 'php://stderr',
...$common,
] : [
'type' => LoggerType::FILE->value,
...$common,
],
'Access' => [
'type' => LoggerType::STREAM->value,
'destination' => 'php://stderr',
'add_new_line' => ! runningInRoadRunner(),
...$common,
],
],
'dependencies' => [
'factories' => [
'Logger_Shlink' => [LoggerFactory::class, 'Shlink'],
'Logger_Access' => [LoggerFactory::class, 'Access'],
NullLogger::class => InvokableFactory::class,
RequestIdProvider::class => ConfigAbstractFactory::class,
],
'aliases' => [
'logger' => 'Logger_Shlink',
Logger::class => 'Logger_Shlink',
LoggerInterface::class => 'Logger_Shlink',
AccessLogMiddleware::LOGGER_SERVICE_NAME => 'Logger_Access',
RequestIdProviderInterface::class => RequestIdProvider::class,
],
],
ConfigAbstractFactory::class => [
RequestIdProvider::class => [RequestIdMiddleware::class],
],
];
})();