Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

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

Started by Anna 3 weeks ago · 4 replies · 269 views
3 weeks 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)

3 weeks 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?

3 weeks 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. 🤷

3 weeks ago

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

3 weeks 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 Anna, 1 week ago
4 328 10 hours ago
Support · by gtx, 2 weeks ago
4 331 1 week ago
Support · by Paul Hodges, 3 weeks ago
13 375 2 weeks ago
Support · by Anna, 4 weeks ago
9 434 2 weeks ago
Support · by TomW, 3 weeks ago
4 275 3 weeks ago