<commit_before><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Messenger\Middleware;

use Symfony\Component\Messenger\MiddlewareInterface;
use Psr\Log\LoggerInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoggingMiddleware implements MiddlewareInterface
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function handle($message, callable $next)
    {
        $this->logger->debug('Starting handling message {class}', array(
            'message' => $message,
            'class' => \get_class($message),
        ));

        try {
            $result = $next($message);
        } catch (\Throwable $e) {
            $this->logger->warning('An exception occurred while handling message {class}', array(
                'message' => $message,
                'exception' => $e,
                'class' => \get_class($message),
            ));

            throw $e;
        }

        $this->logger->debug('Finished handling message {class}', array(
            'message' => $message,
            'class' => \get_class($message),
        ));

        return $result;
    }
}<commit_msg>minor #27066 [Messenger] unwrap ReceivedMessage in LoggingMiddleware to improve log detail (kbond)<commit_after><?php

/*
 * This file is part of the Symfony package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Messenger\Middleware;

use Symfony\Component\Messenger\Asynchronous\Transport\ReceivedMessage;
use Symfony\Component\Messenger\MiddlewareInterface;
use Psr\Log\LoggerInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class LoggingMiddleware implements MiddlewareInterface
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * {@inheritdoc}
     */
    public function handle($message, callable $next)
    {
        $this->logger->debug('Starting handling message {class}', $this->createContext($message));

        try {
            $result = $next($message);
        } catch (\Throwable $e) {
            $this->logger->warning('An exception occurred while handling message {class}', array_merge(
                $this->createContext($message),
                array('exception' => $e)
            ));

            throw $e;
        }

        $this->logger->debug('Finished handling message {class}', $this->createContext($message));

        return $result;
    }

    private function createContext($message): array
    {
        if ($message instanceof ReceivedMessage) {
            $message = $message->getMessage();
        }

        return array(
            'message' => $message,
            'class' => \get_class($message),
        );
    }
}
{'fraction_non_alphanumeric': 0.13215434083601285, 'fraction_numerical': 0.001607717041800643, 'mean_word_length': 2.433774834437086, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3522239', 'n_tokens_mistral': 854, 'n_tokens_neox': 836, 'n_words': 218}