Mity Docs Mity Docs for Mity Digital
Logger for Statamic Documentation

Extend existing event listeners

You may want to extend Logger for Statamic's listeners if you need to:

  • add supplementary data

  • change the view to one within your app

  • do something, but not actually write to the log

When you extend a listener, create this within your app, and then call Logger for Statamic's subscribe method to change the subscription for the event to your own handler. See Subscribing to events for full details.

For full context, you may want to read the Event Listener docs.

Add supplementary data

Logger for Statamic already creates an array of suitable data for each event - and there may be times when you want to add something specific to your app.

Rather than needing to redefine the entire data array (the data method), you can implement your own supplements method that returns an array of supplementary data that gets added to the logged data.

See Supplementary data for a full example.

Change the view

All of Logger for Statamic's listeners have their own view that handles what data is presented to the user within the Control Panel.

Use the view method to change what view gets loaded.

You can choose to:

  • keep the default view

  • publish the view to your own app, and make changes (no changes needed to view)

  • write your own view in your own app (need to overwrite view to have the path to your Blade file)

1public function view(): string
2{
3 // will load `resources/views/listeners/comments.blade.php`
4 return 'listeners.comments';
5}

See customising views for more details.

Change default handle behaviour

By default, the handle method of the listener will write to Logger for Statamic's logs.

There may be instances where you do not want this to happen - such as if you need to store some temporary data, such as the state of the model before the save takes place. This is useful to allow before and after comparisons. We've written a whole new section on temporary data.

If you override handle within your listener, your listener will no longer write to the log.

If you still want to keep the listener's default logging behaviour, make sure to call the parent method:

1public function handle(mixed $event): void
2{
3 // write your own behaviour / logic
4 
5 // call the default implementation to still write to the log
6 parent::handle($event);
7}