phplaravelnewrelic

Where are the PHP 8.2 deprecation logs stored in Laravel 10.22.0?


I am running into a critical issue after upgrading from php 8.0.8 to 8.2 and from laravel 8 to 10.22.0.

I also updated newrelic agemt and removed https://github.com/newrelic/newrelic-monolog-logenricher-php/ as it does not work with php >= 8.1 (requires older monolog 2).

My problem is: Sudden increase in newrelic logs related to php deprecation notices. I did not instrument any extra logging in my code aside the mentioned updates.

enter image description here

Problem 2: I have no idea where they come from! I am using the php-fpm-nginx docker image kristijorgji/php-fpm-8-nginx:0.0.6, code at https://github.com/kristijorgji/docker-images/tree/main/php-fpm-8-nginx + some extra newrelic agent installation not present there.

Things I investigated so far

  1. I looked into the running docker container logs, I see only the nginx outputs. (docker-compose logs --tail=100 api)

  2. I looked inside the docker container and have no logs at /var/log/php or /var/log/nginx/error.log

  3. I looked at storage/logs/laravel.log and it has randomly messages, but never the deprecation notices

4. I debugged in detail what happens within Laravel

First I noticed that /vendor/monolog/monolog/src/Monolog/Logger.php:357 gets called by Laravel at vendor/laravel/framework/src/Illuminate/Log/Logger.php:184 writeLog to write the log of warning level for the deprecatino.

Moving forward the Logger.php:357 has only the Monolog NullHandler as handler vendor/monolog/monolog/src/Monolog/Handler/NullHandler.php so no log is output anywhere enter image description here

So where and how does Newrelic finds and forward these logs then?!?!?! if they are not written anywhere?

Diving further, I noticed that after calling the nullhandler that does nothing, Laravel also fires one MessageLogged event at vendor/laravel/framework/src/Illuminate/Log/Logger.php:248 enter image description here In my development local env I see no listeners for MessageLogged but newrelic is not installed in local.

I believe that maybe Newrelic detects the framework and adds some listener "magically" here by injecting php code in runtime. I see no other log output from my debug and can't tell where and how newrelic finds those deprecations.

Someone can inform me about this if you have more knowledge

So the mistery is: How and where does newrelic find these deprecation logs and forwards them ? Or how can I see them myself during development ?

I want to stop forwarding them to newrelic as it increased by 100 times the cost and they are useless, repeat all the time.

I want to see them in the local development environment so I fix them instead.

PS: I have no idea why newrelic archived https://github.com/newrelic/newrelic-monolog-logenricher-php/

Their log forwarding is broken for newer php versions, the enricher worked great also used the extra context like userId etc that we could attach.


Solution

  • The deprecation logs were going to monolog vendor/monolog/monolog/src/Monolog/Handler/NullHandler.php as I did explain in the updated questions. This handler does not output the logs anywhere.

    If you want to output the deprecation logs in some particular channel, you can change configs/logging.php

    What remains still an open question is: Why does Newrelic listen to Laravel log events and forward logs meant to be sent nowhere (to the null handler that does nothing) ?

    I think this is not a correct behavior. I am in touch with them regarding this.