2016-08-08 04:17:14 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
2017-10-12 03:13:20 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-10-20 05:37:26 -05:00
|
|
|
namespace Shlinkio\Shlink;
|
|
|
|
|
2024-04-07 04:26:17 -05:00
|
|
|
use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
2023-05-07 06:18:19 -05:00
|
|
|
use Laminas\ServiceManager\Factory\InvokableFactory;
|
2022-06-04 01:59:17 -05:00
|
|
|
use Monolog\Level;
|
2016-08-08 04:56:19 -05:00
|
|
|
use Monolog\Logger;
|
2019-09-11 13:25:04 -05:00
|
|
|
use Psr\Log\LoggerInterface;
|
2023-05-07 06:18:19 -05:00
|
|
|
use Psr\Log\NullLogger;
|
2022-06-04 01:59:17 -05:00
|
|
|
use Shlinkio\Shlink\Common\Logger\LoggerFactory;
|
|
|
|
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
2023-05-07 06:18:19 -05:00
|
|
|
use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware;
|
2024-02-04 07:16:42 -06:00
|
|
|
use Shlinkio\Shlink\Common\Middleware\RequestIdMiddleware;
|
2024-10-23 03:53:09 -05:00
|
|
|
use Shlinkio\Shlink\Core\Config\EnvVars;
|
2024-04-07 04:26:17 -05:00
|
|
|
use Shlinkio\Shlink\Core\EventDispatcher\Helper\RequestIdProvider;
|
|
|
|
use Shlinkio\Shlink\EventDispatcher\Util\RequestIdProviderInterface;
|
2019-02-26 15:56:43 -06:00
|
|
|
|
2024-10-23 03:53:09 -05:00
|
|
|
use function Shlinkio\Shlink\Config\env;
|
2023-05-07 06:18:19 -05:00
|
|
|
use function Shlinkio\Shlink\Config\runningInRoadRunner;
|
2019-11-30 10:59:04 -06:00
|
|
|
|
2023-05-07 06:18:19 -05:00
|
|
|
return (static function (): array {
|
2024-10-23 03:53:09 -05:00
|
|
|
$isDev = EnvVars::isDevEnv();
|
2023-05-07 06:18:19 -05:00
|
|
|
$common = [
|
2024-10-23 03:53:09 -05:00
|
|
|
'level' => $isDev ? Level::Debug->value : Level::Info->value,
|
2024-02-04 07:16:42 -06:00
|
|
|
'processors' => [RequestIdMiddleware::class],
|
|
|
|
'line_format' =>
|
|
|
|
'[%datetime%] [%extra.' . RequestIdMiddleware::ATTRIBUTE . '%] %channel%.%level_name% - %message%',
|
2023-05-07 06:18:19 -05:00
|
|
|
];
|
2016-08-08 04:17:14 -05:00
|
|
|
|
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;
|
|
|
|
|
2023-05-07 06:18:19 -05:00
|
|
|
return [
|
2018-11-25 10:14:03 -06:00
|
|
|
|
2023-05-07 06:18:19 -05:00
|
|
|
'logger' => [
|
2024-10-23 03:53:09 -05:00
|
|
|
'Shlink' => $useStreamForShlinkLogger ? [
|
|
|
|
'type' => LoggerType::STREAM->value,
|
|
|
|
'destination' => 'php://stderr',
|
|
|
|
...$common,
|
|
|
|
] : [
|
2023-05-07 06:18:19 -05:00
|
|
|
'type' => LoggerType::FILE->value,
|
|
|
|
...$common,
|
|
|
|
],
|
|
|
|
'Access' => [
|
|
|
|
'type' => LoggerType::STREAM->value,
|
|
|
|
'destination' => 'php://stderr',
|
|
|
|
'add_new_line' => ! runningInRoadRunner(),
|
|
|
|
...$common,
|
|
|
|
],
|
2018-11-25 10:14:03 -06:00
|
|
|
],
|
2023-05-07 06:18:19 -05:00
|
|
|
|
|
|
|
'dependencies' => [
|
|
|
|
'factories' => [
|
|
|
|
'Logger_Shlink' => [LoggerFactory::class, 'Shlink'],
|
|
|
|
'Logger_Access' => [LoggerFactory::class, 'Access'],
|
|
|
|
NullLogger::class => InvokableFactory::class,
|
2024-04-07 04:26:17 -05:00
|
|
|
RequestIdProvider::class => ConfigAbstractFactory::class,
|
2023-05-07 06:18:19 -05:00
|
|
|
],
|
|
|
|
'aliases' => [
|
|
|
|
'logger' => 'Logger_Shlink',
|
|
|
|
Logger::class => 'Logger_Shlink',
|
|
|
|
LoggerInterface::class => 'Logger_Shlink',
|
|
|
|
AccessLogMiddleware::LOGGER_SERVICE_NAME => 'Logger_Access',
|
2024-04-07 04:26:17 -05:00
|
|
|
RequestIdProviderInterface::class => RequestIdProvider::class,
|
2023-05-07 06:18:19 -05:00
|
|
|
],
|
2019-09-11 13:25:04 -05:00
|
|
|
],
|
2018-11-25 10:14:03 -06:00
|
|
|
|
2024-04-07 04:26:17 -05:00
|
|
|
ConfigAbstractFactory::class => [
|
|
|
|
RequestIdProvider::class => [RequestIdMiddleware::class],
|
|
|
|
],
|
|
|
|
|
2023-05-07 06:18:19 -05:00
|
|
|
];
|
|
|
|
})();
|