Mity Docs Mity Docs for Mity Digital
Logger for Statamic Documentation

Subscribing to events

While you can exclude events using Logger for Statamic's configuration file, subscribing to new events is a little more involved.

So involved that it has its own menu section.

But don't panic - we've tried to make it as easy as possible while still making it incredible flexible and powerful for you to get your own events logged within Logger for Statamic.

If you have your own events, you will want to create a new event listener.

If you want to add more data to an existing listener, you will want to extend an existing event listener.

You'll need two things here:

  1. an event to listen for

  2. a listener to handle the event

You can then subscribe using Logger for Statamic's facade's subscribe method - we'd suggest putting this in your Event Service Provider.

1public function boot(): void
2{
3 StatamicLogger::subscribe(\Statamic\Events\UserSaving::class, \App\Listeners\Logger\MyUserSavingListener::class);
4}

If you have multiple listeners, you can pass an array of listeners:

1public function boot(): void
2{
3 StatamicLogger::subscribe(\Statamic\Events\UserSaving::class, [
4 \App\Listeners\Logger\MyUserSavingListener::class,
5 \App\Listeners\Logger\AnotherUserSavingListener::class
6 ]);
7}

Why on earth would you need that? Well in case you want certain actions to be logged at certain times, or reported differently. One example is if you want to store information from before the save until after the save for one log entry, but need to log something else differently, you could do that. That's a really advanced use case, but definitely possible! You might want to check out some advanced use cases.

Note that subscribing to an event that Logger for Statamic is already subscribed to will overwrite any existing listeners.