From 5155b5f6db62b0dd96935f92ab58d0ffd07d549e Mon Sep 17 00:00:00 2001 From: "sergei.baikin" Date: Wed, 18 Sep 2024 15:49:38 +0200 Subject: [PATCH] Add OTEL logging --- README.md | 2 -- src/Symfony/config/services.php | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c1727ed..2a484a1 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,6 @@ return static function (MonologConfig $monolog, ContainerConfigurator $container $monolog->handler('otel') ->type('service') ->id(Handler::class) - ->formatter(OtelFormatter::class) // log start from info messages (debug is lowest level) ->level('info'); @@ -134,7 +133,6 @@ Otel: ``` ->type('service') ->id(Handler::class) - ->formatter(OtelFormatter::class) ``` ### Exception context diff --git a/src/Symfony/config/services.php b/src/Symfony/config/services.php index d45a806..ac01957 100644 --- a/src/Symfony/config/services.php +++ b/src/Symfony/config/services.php @@ -14,6 +14,7 @@ use Psr\Log\LogLevel; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service; +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; return static function (ContainerConfigurator $containerConfigurator) { $s = $containerConfigurator->services(); @@ -35,12 +36,13 @@ $s->set(GuzzleRequestExceptionContext::class) ->tag('gotphoto_logging.exception_context'); + $s->set(OtelFormatter::class); $s->set(Handler::class) ->arg( '$loggerProvider', inline_service(LoggerProviderInterface::class) ->factory([Globals::class, 'loggerProvider']), ) - ->arg('$level', LogLevel::INFO); - $s->set(OtelFormatter::class); + ->arg('$level', LogLevel::INFO) + ->call('setFormatter', [service(OtelFormatter::class)]); };