diff --git a/composer.json b/composer.json index 57ff443a..796caa2d 100644 --- a/composer.json +++ b/composer.json @@ -38,8 +38,6 @@ "mezzio/mezzio-problem-details": "^1.5", "mezzio/mezzio-swoole": "^4.0", "mlocati/ip-lib": "^1.17", - "monolog/monolog": "^2.3", - "nikolaposa/monolog-factory": "^3.1", "ocramius/proxy-manager": "^2.11", "pagerfanta/core": "^3.5", "php-amqplib/php-amqplib": "^3.1", @@ -47,9 +45,9 @@ "predis/predis": "^1.1", "pugx/shortid-php": "^1.0", "ramsey/uuid": "^4.2", - "shlinkio/shlink-common": "^4.4", + "shlinkio/shlink-common": "dev-main#3244088 as 4.5", "shlinkio/shlink-config": "^1.6", - "shlinkio/shlink-event-dispatcher": "^2.3", + "shlinkio/shlink-event-dispatcher": "^2.4", "shlinkio/shlink-importer": "^3.0", "shlinkio/shlink-installer": "^7.1", "shlinkio/shlink-ip-geolocation": "^2.2", diff --git a/config/autoload/logger.global.php b/config/autoload/logger.global.php index e6fcd43c..2da1eda3 100644 --- a/config/autoload/logger.global.php +++ b/config/autoload/logger.global.php @@ -4,72 +4,36 @@ declare(strict_types=1); namespace Shlinkio\Shlink; -use Monolog\Formatter; -use Monolog\Handler; +use Monolog\Level; use Monolog\Logger; -use Monolog\Processor; -use MonologFactory\DiContainerLoggerFactory; use PhpMiddleware\RequestId; use Psr\Log\LoggerInterface; +use Shlinkio\Shlink\Common\Logger\LoggerFactory; +use Shlinkio\Shlink\Common\Logger\LoggerType; -use const PHP_EOL; - -$processors = [ - 'exception_with_new_line' => [ - 'name' => Common\Logger\Processor\ExceptionWithNewLineProcessor::class, - ], - 'psr3' => [ - 'name' => Processor\PsrLogMessageProcessor::class, - ], - 'request_id' => RequestId\MonologProcessor::class, -]; -$formatter = [ - 'name' => Formatter\LineFormatter::class, - 'params' => [ - 'format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%' . PHP_EOL, - 'allow_inline_line_breaks' => true, - ], +$common = [ + 'level' => Level::Info->value, + 'processors' => [RequestId\MonologProcessor::class], + 'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%', ]; return [ 'logger' => [ 'Shlink' => [ - 'name' => 'Shlink', - 'handlers' => [ - 'shlink_handler' => [ - 'name' => Handler\RotatingFileHandler::class, - 'params' => [ - 'level' => Logger::INFO, - 'filename' => 'data/log/shlink_log.log', - 'max_files' => 30, - 'file_permission' => 0666, - ], - 'formatter' => $formatter, - ], - ], - 'processors' => $processors, + 'type' => LoggerType::FILE->value, + ...$common, ], 'Access' => [ - 'name' => 'Access', - 'handlers' => [ - 'access_handler' => [ - 'name' => Handler\StreamHandler::class, - 'params' => [ - 'level' => Logger::INFO, - 'stream' => 'php://stdout', - ], - 'formatter' => $formatter, - ], - ], - 'processors' => $processors, + 'type' => LoggerType::STREAM->value, + ...$common, ], ], 'dependencies' => [ 'factories' => [ - 'Logger_Shlink' => [DiContainerLoggerFactory::class, 'Shlink'], - 'Logger_Access' => [DiContainerLoggerFactory::class, 'Access'], + 'Logger_Shlink' => [LoggerFactory::class, 'Shlink'], + 'Logger_Access' => [LoggerFactory::class, 'Access'], ], 'aliases' => [ 'logger' => 'Logger_Shlink', diff --git a/config/autoload/logger.local.php.dist b/config/autoload/logger.local.php.dist index 1da0384b..7288ed06 100644 --- a/config/autoload/logger.local.php.dist +++ b/config/autoload/logger.local.php.dist @@ -2,33 +2,18 @@ declare(strict_types=1); -use Monolog\Handler\StreamHandler; -use Monolog\Logger; +use Monolog\Level; +use Shlinkio\Shlink\Common\Logger\LoggerType; $isSwoole = extension_loaded('openswoole'); -// For swoole, send logs to standard output -$handler = $isSwoole - ? [ - 'name' => StreamHandler::class, - 'params' => [ - 'level' => Logger::DEBUG, - 'stream' => 'php://stdout', - ], - ] - : [ - 'params' => [ - 'level' => Logger::DEBUG, - ], - ]; - return [ 'logger' => [ 'Shlink' => [ - 'handlers' => [ - 'shlink_handler' => $handler, - ], + // For swoole, send logs as stream + 'type' => $isSwoole ? LoggerType::STREAM->value : LoggerType::FILE->value, + 'level' => Level::Debug->value, ], ], diff --git a/config/autoload/request_id.global.php b/config/autoload/request_id.global.php index f057bb09..5525849a 100644 --- a/config/autoload/request_id.global.php +++ b/config/autoload/request_id.global.php @@ -5,6 +5,7 @@ declare(strict_types=1); use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\Factory\InvokableFactory; use PhpMiddleware\RequestId; +use Shlinkio\Shlink\Common\Logger\Processor\BackwardsCompatibleMonologProcessorDelegator; return [ @@ -20,6 +21,11 @@ return [ RequestId\RequestIdMiddleware::class => ConfigAbstractFactory::class, RequestId\MonologProcessor::class => ConfigAbstractFactory::class, ], + 'delegators' => [ + RequestId\MonologProcessor::class => [ + BackwardsCompatibleMonologProcessorDelegator::class, + ], + ], ], ConfigAbstractFactory::class => [ diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index 89807b26..b9bac12d 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -8,8 +8,7 @@ use GuzzleHttp\Client; use Laminas\ConfigAggregator\ConfigAggregator; use Laminas\Diactoros\Response\EmptyResponse; use Laminas\ServiceManager\Factory\InvokableFactory; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; +use Monolog\Level; use PHPUnit\Runner\Version; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -20,6 +19,7 @@ use SebastianBergmann\CodeCoverage\Filter; use SebastianBergmann\CodeCoverage\Report\Html\Facade as Html; use SebastianBergmann\CodeCoverage\Report\PHP; use SebastianBergmann\CodeCoverage\Report\Xml\Facade as Xml; +use Shlinkio\Shlink\Common\Logger\LoggerType; use function Laminas\Stratigility\middleware; use function Shlinkio\Shlink\Config\env; @@ -76,16 +76,10 @@ $buildDbConnection = static function (): array { }; }; -$buildTestLoggerConfig = fn (string $handlerName, string $filename) => [ - 'handlers' => [ - $handlerName => [ - 'name' => StreamHandler::class, - 'params' => [ - 'level' => Logger::DEBUG, - 'stream' => sprintf('data/log/api-tests/%s', $filename), - ], - ], - ], +$buildTestLoggerConfig = static fn (string $filename) => [ + 'level' => Level::Debug->value, + 'type' => LoggerType::STREAM->value, + 'destination' => sprintf('data/log/api-tests/%s', $filename), ]; return [ @@ -183,8 +177,8 @@ return [ ], 'logger' => [ - 'Shlink' => $buildTestLoggerConfig('shlink_handler', 'shlink.log'), - 'Access' => $buildTestLoggerConfig('access_handler', 'access.log'), + 'Shlink' => $buildTestLoggerConfig('shlink.log'), + 'Access' => $buildTestLoggerConfig('access.log'), ], ]; diff --git a/docker/config/shlink_in_docker.local.php b/docker/config/shlink_in_docker.local.php index 73cc3fdc..4fba24b6 100644 --- a/docker/config/shlink_in_docker.local.php +++ b/docker/config/shlink_in_docker.local.php @@ -4,22 +4,13 @@ declare(strict_types=1); namespace Shlinkio\Shlink; -use Monolog\Handler\StreamHandler; -use Monolog\Logger; +use Shlinkio\Shlink\Common\Logger\LoggerType; return [ 'logger' => [ 'Shlink' => [ - 'handlers' => [ - 'shlink_handler' => [ - 'name' => StreamHandler::class, - 'params' => [ - 'level' => Logger::INFO, - 'stream' => 'php://stdout', - ], - ], - ], + 'type' => LoggerType::STREAM->value, ], ],