Skip to content

Commit

Permalink
Send logs to dedicated monolog channel in symfony bundle (#369)
Browse files Browse the repository at this point in the history
* refactor LoggingService

* use LoggingService to add span event

* add monolog channel to symfony extension

* fix phpdi container implementation for optional reference

* fix phpstan

* add test compat with monolog 2.0

* drop code duplication for LoggerExample.php

* add `critical` method to LoggingGateway

* log to console with laravel

* remove EchoLogger
  • Loading branch information
jlabedo authored Sep 4, 2024
1 parent 3089cfe commit 8a91789
Show file tree
Hide file tree
Showing 64 changed files with 469 additions and 1,454 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
"open-telemetry/exporter-otlp": "^1.0.0",
"nesbot/carbon": "^2.71",
"moneyphp/money": "^4.1.0",
"timacdonald/log-fake": "^2.0"
"timacdonald/log-fake": "^2.0",
"symfony/monolog-bundle": "^3.10"
},
"conflict": {
"symfony/doctrine-messenger": ">7.0.5 < 7.1.0"
Expand Down
180 changes: 0 additions & 180 deletions packages/Amqp/tests/Fixture/Support/Logger/LoggerExample.php

This file was deleted.

2 changes: 1 addition & 1 deletion packages/Amqp/tests/Integration/AmqpMessageChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Ecotone\Messaging\Handler\Recoverability\RetryTemplateBuilder;
use Ecotone\Messaging\PollableChannel;
use Ecotone\Messaging\Support\MessageBuilder;
use Ecotone\Test\LoggerExample;
use Enqueue\AmqpExt\AmqpConnectionFactory;
use Interop\Amqp\Impl\AmqpQueue;
use Ramsey\Uuid\Uuid;
use Test\Ecotone\Amqp\AmqpMessagingTest;
use Test\Ecotone\Amqp\Fixture\DeadLetter\ErrorConfigurationContext;
use Test\Ecotone\Amqp\Fixture\Order\OrderService;
use Test\Ecotone\Amqp\Fixture\Support\Logger\LoggerExample;

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function transactional(MethodInvocation $methodInvocation, Message $messa
$logger->info(
'Implicit Commit was detected, skipping manual one.',
$message,
$exception
['exception' => $exception],
);

try {
Expand All @@ -117,7 +117,7 @@ public function transactional(MethodInvocation $methodInvocation, Message $messa
$logger->info(
'Exception has been thrown, rolling back transaction.',
$message,
$exception
['exception' => $exception]
);

/** Doctrine hold the state, so it needs to be cleaned */
Expand Down
8 changes: 4 additions & 4 deletions packages/Dbal/src/Deduplication/DeduplicationInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
use Ecotone\Messaging\Attribute\AsynchronousRunningEndpoint;
use Ecotone\Messaging\Attribute\Deduplicated;
use Ecotone\Messaging\Attribute\IdentifiedAnnotation;
use Ecotone\Messaging\Handler\Logger\LoggingGateway;
use Ecotone\Messaging\Handler\Processor\MethodInvoker\MethodInvocation;
use Ecotone\Messaging\Message;
use Ecotone\Messaging\MessageHeaders;
use Ecotone\Messaging\Scheduling\Clock;
use Enqueue\Dbal\DbalContext;
use Interop\Queue\ConnectionFactory;
use Interop\Queue\Exception\Exception;
use Psr\Log\LoggerInterface;

use function spl_object_id;

Expand All @@ -36,11 +36,11 @@ class DeduplicationInterceptor
public const DEFAULT_DEDUPLICATION_TABLE = 'ecotone_deduplication';
private array $initialized = [];

public function __construct(private ConnectionFactory $connection, private Clock $clock, private int $minimumTimeToRemoveMessageInMilliseconds, private LoggerInterface $logger)
public function __construct(private ConnectionFactory $connection, private Clock $clock, private int $minimumTimeToRemoveMessageInMilliseconds, private LoggingGateway $logger)
{
}

public function deduplicate(MethodInvocation $methodInvocation, Message $message, ?Deduplicated $deduplicatedAttribute, ?IdentifiedAnnotation $identifiedAnnotation, ?AsynchronousRunningEndpoint $asynchronousRunningEndpoint)
public function deduplicate(MethodInvocation $methodInvocation, Message $message, ?Deduplicated $deduplicatedAttribute, ?IdentifiedAnnotation $identifiedAnnotation, ?AsynchronousRunningEndpoint $asynchronousRunningEndpoint): mixed
{
$connectionFactory = CachedConnectionFactory::createFor(new DbalReconnectableConnectionFactory($this->connection));
$contextId = spl_object_id($connectionFactory->createContext());
Expand Down Expand Up @@ -77,7 +77,7 @@ public function deduplicate(MethodInvocation $methodInvocation, Message $message
'consumer_endpoint_id' => $consumerEndpointId,
'routing_slip' => $routingSlip,
]);
return;
return null;
}

try {
Expand Down
4 changes: 2 additions & 2 deletions packages/Dbal/src/Deduplication/DeduplicationModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ModuleReferenceSearchService;
use Ecotone\Messaging\Handler\InterfaceToCallRegistry;
use Ecotone\Messaging\Handler\Logger\LoggingGateway;
use Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundInterceptorBuilder;
use Ecotone\Messaging\Precedence;
use Ecotone\Messaging\Scheduling\Clock;
use Psr\Log\LoggerInterface;

#[ModuleAnnotation]
/**
Expand Down Expand Up @@ -64,7 +64,7 @@ public function prepare(Configuration $messagingConfiguration, array $extensionO
new Reference($connectionFactory),
new Reference(Clock::class),
$minimumTimeToRemoveMessageFromDeduplication,
new Reference(LoggerInterface::class),
new Reference(LoggingGateway::class),
]
)
);
Expand Down
Loading

0 comments on commit 8a91789

Please sign in to comment.