Change Logging and Stack Trace Depth based on error level

Hey there! I’m currently tracking my logs by right clicking the Site > Open Site SSH. And then going to the logs folder. Then tail -f debug.log it. This is fantastic and easy. However I notice that every level of “error” shows a complete stack trace, which is cumbersome. I understand in some circumstances it’s needed. But for Deprecated Errors, it’s not!

Is it possible to change the level of logging? I’d love to still see PHP Deprecated errors, Notices, Fatal Errors. But only want to see the Stack trace on Fatal Errors. This is somewhat mandatory because some plugins we have no control over love clouding up the error log with Deprecated errors. I can modify my tail -f call to tail -f debug.log | grep -Ev '(PHP Deprecated)' which just hides the Deprecated errors, but it doesn’t hide the Stack trace that accompanies it.

Thanks!
Matt

Of course I figure it out as soon as I post this! Hopefully this helps others in some way…

You can edit Local’s php.ini file in (Windows): [Local Folder]/conf/php/[php version]/php.ini and change your error logging level. However this may not affect how much WordPress is logging (it didn’t change it for me).

This was my fix, probably not the best approach and willing to hear other solutions, but this worked for me in a dev environment.

Open up /wp-includes/load.php. On line 320-321 you’ll see:
if ( WP_DEBUG ) { error_reporting( E_ALL );
I changed it to:

if ( WP_DEBUG ) { error_reporting( E_ERROR | E_WARNING );

On a production environment - definitely do not change core WordPress files. I wonder if there’s a way to do this in wp-config.php

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.