Debugging with eZDebug
This page is for PHP developers who need to see what their code does inside a request. eZDebug
(lib/ezutils/classes/ezdebug.php) collects messages, timing points and accumulators,
writes warnings and errors to the logs, and shows everything in the debug bar when debug output is on. The bar itself is
described on The debug bar for PHP developers.
Contents
- Writing messages
- Conditional debug messages
- Timing points and accumulators
- Turning debug output on
- Who gets debug output
- Debugging on the command line
- Other tools
- A working order
Writing messages
eZDebug::writeNotice( 'Imported ' . $count . ' items', __METHOD__ );
eZDebug::writeWarning( 'Item ' . (int)$id . ' had no title; used the id', __METHOD__ );
eZDebug::writeError( 'The feed could not be read: ' . $message, __METHOD__ );
eZDebug::writeDebug( $details, __METHOD__ );| Method | Level | Shown and logged |
|---|---|---|
writeError() | error | in the debug output; written to var/log/error.log always (the shipped AlwaysLog[]=error) |
writeWarning() | warning | in the debug output; written to var/log/warning.log when the level is logged |
writeNotice() | notice | in the debug output; logged only when listed in AlwaysLog[] (it fills logs quickly) |
writeDebug() | debug | in the debug output; logged only when listed in AlwaysLog[] |
site.ini [DebugSettings] AlwaysLog[] lists the levels that are logged even when debug output is off; the shipped value
is error. PHP deprecations go to var/log/deprecated.log (DeprecatedLog=enabled), each distinct message once per
request. Pass __METHOD__ as the label: it names the class and method in every line, so a reader of the log finds the
code. Never write passwords, tokens or personal data into a message.
Conditional debug messages
Verbose diagnostics that you want only when you ask for them use a debug condition:
eZDebugSetting::writeDebug( 'extension-acmereport', $details, __METHOD__ );The message is written only when the condition is enabled in debug.ini:
# settings/override/debug.ini.append.php (development)
[GeneralCondition]
extension-acmereport=enabledThe kernel uses conditions such as kernel-content-view, kernel-urltranslator and workflow-event; ezformtoken uses
ezformtoken. The debug bar finds every condition of [GeneralCondition] and shows it as a switch.
Timing points and accumulators
eZDebug::addTimingPoint( 'acmereport: before import' );
eZDebug::createAccumulatorGroup( 'acmereport_total', 'Acme report' );
eZDebug::accumulatorStart( 'acmereport_fetch', 'acmereport_total', 'Fetch the feed' );
$feed = acmeReportFeed::fetch( $url );
eZDebug::accumulatorStop( 'acmereport_fetch' );Timing points mark moments of the request; accumulators add up the time of a piece of code across all its calls (and count them). Both appear in the bar's Timing tab. The database drivers record their statements as accumulators, which is where the bar's SQL figures come from.
Turning debug output on
On a development machine only (better in a site.ini.dev.append.php, see
Setting up a PHP development checkout):
[DebugSettings]
DebugOutput=enabled
[TemplateSettings]
ShowUsedTemplates=enabled
ShowTemplatePathComments=enabled
[DatabaseSettings]
SQLOutput=enabledShowTemplatePathComments writes the template path as an HTML comment around each template's output
(Template path comments). Never enable debug output for visitors of a
production site: it shows internals.
Who gets debug output
| Setting | Meaning |
|---|---|
[DebugSettings] DebugByIP=enabled with DebugIPList[] | only these addresses or networks (IPv4 and IPv6, CIDR, with an optional label and expiry) |
DebugByUser=enabled with DebugUserIDList[] | only these users |
DebugIPList[]=commandline | the command line too |
DebugIPList[]=203.0.113.7/32 ; Laptop ; expires=2026-10-02T15:00Debugging on the command line
Every eZScript command takes -d (or --debug) with the items to show, for example -d all or
-d error,warning,timing:
php bin/php/console ext:acmereport:report --month=2026-09 -d allOther tools
- Xdebug: works as usual on PHP-FPM and the command line;
tests/xdebug.iniis the configuration the PHPUnit children use. Keep it off when you measure performance. - The logs: everything that went wrong without debug output is in
var/log/(Logs, the log viewer and request logs). - An error reference: error pages show a reference that
php bin/php/explogs.php --reference=<reference>finds in the logs (Finding an error by its reference).
A working order
- Reproduce on a development copy with debug output on.
- Read the Messages tab for errors and warnings from your files.
- Check the Templates tab and the template path comments: is your code even the one that runs?
- Add
eZDebug::writeDebug()or a condition around the suspect code. - Under Velocity, compare with PHP's built-in server (
--engine=php): if the bug disappears, look for state kept between requests (Static state traps). - Write a test that fails, fix, and keep the test.
Related pages
- eZDebug and logging reference
- Debugging and logs (application creators)
- Debug output improvements
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.