Moodle Debugbar
Debugbar is a lightweight local developer toolbar that surfaces request data, log entries, and profiling metrics while building Moodle features.
Warning: I built this plugin entirely during hobby hours for personal learning, so if you have better ideas for configuration hooks for bootstrapping, please open an issue or send a merge request.
Note: The repository keeps the vendor directory committed because some companies, and developers cannot run Composer; in a full Composer-based workflow you can remove that folder and install dependencies via composer during deployment instead.
- PHP 7.4 or later (matches
composer.jsonplatform requirement). php-debugbar/php-debugbar ^1.0(installed automatically via Composer inside this plugin).
- Copy or
git clonethis folder intomoodle/local/debugbaron your development site. - From the plugin directory run
composer install --no-devto pullphp-debugbar/php-debugbarand autoload files. - Execute
php admin/cli/upgrade.phpfrom the Moodle root so the plugin registers itself. - Log in as an administrator and confirm
Site administration -> Plugins -> Local plugins -> Debug Barshows up.
- Integrates the upstream
php-debugbarpackage to display runtime information in Moodle pages. - Provides admin settings to limit access by user ID and to require developer debugging mode.
- Logs structured messages, automatic measures, and manual profiling spans for each request.
- Ships with a live demo inside
settings.phpso you can inspect how logging and measurement APIs behave.
- Open the Debug Bar settings page and add
?enable_debugbar=1to the URL so the toolbar appears. - Set
Allowed user IDto your testing account to control who sees the bar. - Turn on
Enable when debuggingonly when$CFG->debugdeveloperis enabled so the output stays focused on learning sessions.
- Browse any page with the query parameter
?enable_debugbar=1and make sure you use the allowed user account. - Watch the Messages tab for log entries and the Timeline tab for performance bars while you click through Moodle.
- Disable the plugin or remove the query parameter when you are finished to keep your site fast.
Check settings.php to see how every feature is implemented:
// Test the Debugbar functionality in settings page.
$manager = \local_debugbar\debugbar_manager::instance();
// Test logging with different levels.
$manager->log_message('info', 'Settings page loaded', ['time' => time(), 'user' => $USER->id]);
$manager->log_message('debug', 'Testing Debugbar in settings.php', [
'hassiteconfig' => $hassiteconfig,
'plugin' => 'local_debugbar'
]);
// Test performance measurement.
$manager->measure('load_settings', 'Load Debugbar Settings', function() use ($settings) {
// Simulate some work.
usleep(5000); // 5ms
return true;
});
// Test manual start/stop.
$manager->start_measure('config_check', 'Check Configuration');
$alloweduser = get_config('local_debugbar', 'alloweduserid');
$enabledebugging = get_config('local_debugbar', 'enablewhendebugging');
$manager->stop_measure('config_check', [
'alloweduser' => $alloweduser,
'enabledebugging' => $enabledebugging
]);
// Log configuration status.
$manager->log_message('info', 'Current configuration', [
'allowed_user_id' => $alloweduser ?: 123,
'enable_when_debugging' => $enabledebugging ? 'Yes' : 'No',
'debugbar_enabled' => $manager->is_enabled() ? 'Yes' : 'No'
]);
This snippet shows logging, automatic measures, manual measures, and configuration checks that you can copy into your own code.
Use this plugin only on development or hobby Moodle instances because it logs detailed request data and adds overhead.