Skip to content
On this page

Debugging Tools

Forme includes useful debugging and logging tools. A couple of these are available in dev mode only.

Switching Modes

You can switch modes by updating the WP_ENV constant in your wp-config.php (or the WP_ENV .env variable if you're using bedrock). See also WP_DEBUG and SAVEQUERIES for Debugbar.

Whoops

In dev mode, fatal exceptions are rendered via the awesome Whoops, so you get useful debugging data in a smart looking page.

Whoops

WARNING

Lower levels (e.g. notices and warnings) have been switched off and won't trigger Whoops, mainly due to WordPress core being absolutely full of them - our app would never run if we enabled them. However, these are available for you in the Debugbar.

You can configure your favourite editor to open files directly from Whoops editor pages - for this you need to set the WHOOPS_EDITOR environment variable in your .env

sh
# can be one of emacs, idea, macvim, phpstorm, sublime, textmate, xdebug, vscode, atom, espresso or netbeans
WHOOPS_EDITOR=vscode

Debugbar

DebugBar is a WordPress plugin, and is available for you in wp-admin. Activate it and you'll get query, cache, and other helpful debugging information.

When WP_DEBUG is enabled it also tracks PHP Warnings and Notices to make them easier to find.

When SAVEQUERIES is enabled, mysql queries are tracked and displayed.

Var Dumper

The Symfony VarDumper component provides a better dump() function that you can use instead of var_dump while you're in dev mode.

You can also dump and die with dd()!

Monolog

Monolog is available for all your logging needs, you can typehint for Psr\Log\LoggerInterface\LoggerInterface or grab an instance via Forme\log().

php
use Psr\Log\LoggerInterface;

final class FooBarService
{
    public function __construct(private LoggerInterface $logger)
    {
    }
}

By default, logs are output to FORME_PRIVATE_ROOT/logs/forme_DATE.log files if WP_ENV is not set to production.

If WP_ENV is set to production, then logs will be stored as Events.

You can override this behaviour by setting the LOG_HANDLER environment variable to either file or event in your .env configuration.

Downgrading Monolog

Many popular WordPress plugins unfortunately don't prefix their classes and have a tendency to hijack the global namespace with older versions of various libraries. This can create dependency conflicts which then have to be manually resolved. The one we've found that recurs fairly frequently for us is around psr/log, which is a Monolog dependency.

Out of the box, Forme will use ^v3.3 of Monolog which depends on psr/log v3, but if you find this conflicts with your third party plugin dependencies you can downgrade it by explicitly requiring "monolog" : "^v2.9" in your base composer.json, which uses psr/log v2.

Made by Moussa Clarke @ Sanders Web Works with ❤️