Mity Docs Mity Docs for Mity Digital
Logger for Statamic Documentation

Customising views

Logger for Statamic's listeners each have their own Blade template used for rendering the message within the reader view.

If you're creating your own listeners, you'll need to write your own Blade template for your listener.

If you're extending an existing listener, you can choose to publish Logger for Statamic's views (and then make changes), or write your own Blade template.

See Event Listener for details of the listener's view method.

View anatomy

A view is simply a Blade template. Nothing fancy.

It gives you the ability to template each listener's log message to make it beautifully human-friendly, showing exactly what you need it to show that is relevant to your users.

1<div>{{ $handler->action() }} '{{ $data->name }}'</div>
2<div class="text-xs text-gray-500">{{ __('statamic-logger::listeners.id') }}: {{ $data->id }}</div>

For a Collection event can output:

1<div>Created 'Pages'</div>
2<div class="text-xs text-gray-500">ID: pages</div>

Note: If you're including custom CSS, you'll need to make sure this is included within the CP stylesheet, or inline in your template.

View data

When your view is rendered, Logger for Statamic passes supporting data along to your Blade template.

$data

The $data variable is a \MityDigital\StatamicLogger\Support\Entry object. It contains publicly accessible variables for each of the properties stored within the log entry.

Within your Blade template, you can directly access these. For the "name" property:

1{{ $data->name }}

If your $data includes nested data, these will be a stdClass, accessible via the same method. The data for an Entry includes a collection property, which also has a name. You can access this by:

1{{ $data->collection->name }}

Refer to each listener's template for what data is accessible.

You can also see the raw $data object in the viewer by selecting the "Show raw message?" option.

$event

The name of the event, such as \Statamic\Events\EntrySaved.

$handler

An instance of the listener that has handled the event - this will give you access to helpful methods like action to receive the nice human-friendly verb of what the action did.

Publishing built-in views

If you want to use Logger for Statamic's views as a starting point, you can publish these to your app:

1php artisan vendor:publish --tag=statamic-logger-listener-views

This will copy all of Logger for Statamic's views to resources/views/vendor/statamic-logger/listeners.

If you only want to make changes to one view, you can safely delete the others from your local app. They'll fall back to Logger for Statamic's built-in views.

Locations

Under-the-hood, your listener's view method response will be passed to Laravel's view() helper to render the template.

If you decide to publish the built-in views, you won't need to change your listener's view method - the namespaced view, such as statamic-logger::listeners.entry, will:

  1. try to look in your resources/views/vendor/statamic-logger/listeners folder for a view, and if that doesn't exist

  2. load Logger for Statamic's built in view

If you want to put your Blade templates in your own location, your listener's view method will need to return a path relative to your app's resources/views folder:

Returning listeners.comment will expect resources/views/listeners/comment.blade.php exists.