Lesson 1.3: Debug output and logs
A live site hides its errors. A development installation must show them. In this lesson learners switch on the
debug output with exp:ini, read the report the Exp Debug bar shows under every page, follow the log files while
they reload, and write their own debug lines from PHP and from a template.
At a glance
| Course | Developers |
| Module | Module 1: The development installation |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Beginner |
| Audience | PHP developers new to Exponential |
| Prerequisites | Lesson 1.2: a running development installation |
Learning objectives
After this lesson, learners can:
- switch debug output, used templates and template path comments on and off with
exp:ini; - read the errors, templates, timing and SQL parts of the debug report;
- follow
var/log/error.logwithtailorexp:logswhile reproducing a problem; - write debug lines with
eZDebugand a log file of their own witheZLog::write(); - restrict debug output to their own address or user on a shared machine.
Trainer's notes
How to present it
Sources: Debug output and logs for developers, The Exp Debug bar and The log viewer.
The settings (4 minutes). All in
site.ini; show the defaults:Block Setting Default Meaning [DebugSettings]DebugOutputdisabledShow the debug report at all [DebugSettings]DebugByIP+DebugIPList[]disabledOnly for these addresses [DebugSettings]DebugByUser+DebugUserIDList[]disabledOnly for these user IDs [TemplateSettings]ShowUsedTemplatesdisabledList every template the page used [TemplateSettings]ShowTemplatePathCommentsdisabledHTML comments naming each part's template [TemplateSettings]TemplateCompileenabledCompiled template cache [DatabaseSettings]SQLOutputdisabledEvery SQL query with its time Switching them on (3 minutes). Show the
exp:ini setcommands of the exercise and the--dry-runoption.exp:iniwritessettings/override/site.ini.append.phpand keeps a backup.The report (4 minutes). Reload a page: errors first, then the templates table (requested template, used template, override), timing points, SQL. A query that runs a hundred times is a loop that should fetch once.
Logs (2 minutes).
var/log/error.logalways gets errors ([DebugSettings] AlwaysLog[]=error).deprecated.logis the to-do list for the next PHP version. Setup > Log files shows the same files in the browser.Your own lines (2 minutes).
eZDebug::writeDebug(),writeNotice(),writeWarning(),writeError(), with__METHOD__as the label;{debug-log var=$node msg='...'}in a template.
Common questions
Can visitors see the debug output? Yes, everyone who can open the page, unless DebugByIP or DebugByUser
limits it. Debug output reveals paths, SQL and settings: never on a live site.
Why does my template change not show? With TemplateCompile=enabled the compiled version is used until the
template cache is cleared. Developers often set TemplateCompile=disabled while editing.
Where is the log of a command line script? The same var/log/ files; [DebugSettings] ScriptDebugOutput
adds debug output to scripts.
Pitfalls
- Forgetting to clear the INI cache. After a settings change, run
php bin/php/ezcache.php --clear-tag=ini; otherwise the old values are used. - Debug lines left in code. Ask learners to remove every
writeDebug()before they commit. - Personal data in logs. Never write passwords, keys or personal data to a log file.
Hands-on exercise
On the development installation from lesson 1.2, from its root folder.
Look where the setting comes from:
php bin/php/console exp:ini where site.ini/DebugSettings/DebugOutput.Preview the change:
php bin/php/console exp:ini set site.ini/DebugSettings/DebugOutput enabled global --dry-run.Switch on the three settings:
php bin/php/console exp:ini set site.ini/DebugSettings/DebugOutput enabled global php bin/php/console exp:ini set site.ini/TemplateSettings/ShowUsedTemplates enabled global php bin/php/console exp:ini set site.ini/TemplateSettings/ShowTemplatePathComments enabled global php bin/php/ezcache.php --clear-tag=ini php bin/php/ezcache.php --clear-tag=templateReload the front page of the site. Open the debug bar and find the list of used templates.
View the page source and search for
START. Write down the template of the page footer.In a second terminal, follow the error log:
tail -f var/log/error.log.Open an address that does not exist, for example
/site/content/view/full/999999, and watch both the page and the terminal.List the log files the viewer may open:
php bin/php/console exp:logs --list.Show the last five entries of the error log through the viewer:
php bin/php/console exp:logs --tail=var/log/error.log --lines=5.Switch
ShowTemplatePathCommentsoff again with the same command anddisabled, and clear the template cache.
Expected result
- Step 1 lists
settings/site.iniwithDebugOutput=disabledand, after step 3, an override withenabledin effect. - Step 4: the debug bar appears at the bottom of every page, its templates list names
pagelayout.tpland the node view templates. - Step 5: comments such as
<!-- START design/.../footer.tpl -->in the source. - Step 7: the not-found page;
404.logorerror.loggains a line depending on the settings. - The trainer checks the
exp:ini whereoutput of two learners.
Quiz
- Which setting shows the debug report under every page?
A.
[TemplateSettings] DebugB.[DebugSettings] DebugOutputC.[DatabaseSettings] SQLOutputD.[DebugSettings] AlwaysLog[] - Which two settings limit the debug output to some people?
- What should follow every settings change with
exp:ini set? - Which
eZDebugmethod writes toerror.logeven without debug output? - True or false: template path comments are safe to leave on for a feed or a live siteaccess.
Answers
- B.
DebugOutput=enabledshows the report, the Exp Debug bar. DebugByIPwithDebugIPList[], andDebugByUserwithDebugUserIDList[].- Clearing the INI cache,
php bin/php/ezcache.php --clear-tag=ini. eZDebug::writeError(): errors are always logged (AlwaysLog[]=error).- False. They add markup to every template; development only (Template path comments).
Further reading
- Debug output and logs for developers: every setting and log file.
- The Exp Debug bar: its tabs and its settings tab.
- The log viewer and Finding an error by its reference.
Related pages
- Module 1: The development installation
- Developers: course overview
- Trainers: start here
- 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.