Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoLogger 9 Levels deep aborting normalization

I am trying to log a request that we are sending via guzzle which is deeply nested (upto 10-11 levels deep to be precise).

Logging the request with Monolog spits out:

Over 9 levels deep, aborting normalization

on the deeply nested attributes.

The code is dead simple

// $requestData being the data I am sending via guzzle.
Log::info("Ekart Booking API:", $requestData);

Is there a way I can increase the Monolog's normalization depth?

like image 806
Saud Qureshi Avatar asked Oct 27 '25 10:10

Saud Qureshi


2 Answers

You can json_encode it:

Log::info("Ekart Booking API:" . json_encode($requestData));
like image 78
Diogo Gomes Avatar answered Oct 30 '25 01:10

Diogo Gomes


You can play with this, it will change NormalizerFormatter::$maxNormalizeDepth on every formatters it found (that's maybe not what you want)

if ($logger instanceof \Monolog\Logger) {
    foreach ($logger->getHandlers() as $handler) {
        if ($handler instanceof \Monolog\Handler\FormattableHandlerInterface) {
            $formatter = $handler->getFormatter();
            if ($formatter instanceof \Monolog\Formatter\NormalizerFormatter) {
                $formatter->setMaxNormalizeDepth(50);
            }
        }
    }
}
like image 27
Axi Avatar answered Oct 29 '25 23:10

Axi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!