Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

plugin/theme development: logging works, sending messages to debugger does not

Started by Anna 2 months ago · 4 replies · 419 views
2 months ago

In my theme.php I want to do something whenever the theme config gets saved. I tried two hooks for that: onAdminSave and onApiConfigUpdated. Both let me send messages to the logs via $this->grav['log']->info('test log message');.

However, $this->grav['log']->addMessage($event, 'info'); seems to do nothing in both hooks – at least I can’t find any output anywhere, neither in the little bug message box nor in Clockwork. I got both methods from the Grav docs on debugging.

I think it’s still possible that I just don’t know where to look, but I am running out of ideas as to where this might still be hiding…

(the thing I want to do)

2 months ago

I cannot reproduce the issue.

Using the following snippet, a message is being written into /logs/grav.log.

PHP
public function onThemeInitialized()
{
    $this->enable([
        'onAdminSave'  => ['onAdminSave', 0],
    ]);
}

public function onAdminSave() {
    $this->grav['log']->info('test log message');
}

grav.log => "[2026-07-23T20:23:44.304286+00:00] grav.INFO: test log message [] []"

Are you sure you've registered for the event and the function is being called?

2 months ago

Augh, I made a typo! Sorry about that.

This is my function:

PHP
public function onApiConfigUpdated(Event $event): void
{
    $this->grav['log']->info('still testing');
    $this->grav['debugger']->addMessage($event, 'info');
}

The logging happens as expected. The message to the debugger turns up nowhere. (At least nowhere I can find, like I said.)

If I use onAdminSave instead, the result is the same. 🤷

2 months ago

Make sure you have debugger set to 'clockwork' and the debugger is enabled in the system configuration. Can you confirm both of those?

2 months ago

I've never been able to write debug messages to clockwork nor debugbar from within PHP. Yes, debugger is enabled with clockwork as provider.

It never bothered me though, because I always set breakpoints, with step-by-step debugging and watching variables in PHP using Xdebug.

In Twig I dump variables using {{ dump(variable) }} into clockwork, which works good enough.

Suggested topics

Topic Participants Replies Views Activity
Support · by Marcel, 4 days ago
0 81 4 days ago
Support · by JakobDB, 6 days ago
1 89 5 days ago
Support · by ramenos, 7 days ago
3 103 6 days ago
Support · by gravinator, 2 weeks ago
3 228 7 days ago
Support · by Roger Parkinson, 2 weeks ago
3 308 2 weeks ago