# LogViewerEvent events

> 4 FeatherPanel plugin events on LogViewerEvent (2 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/log-viewer/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 2 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `LogViewerEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\LogViewerEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(LogViewerEvent::onLogCleared(), function ($logType, $logFile, $clearedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:log_viewer:cleared ' . json_encode(['log_file' => $logFile]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `LogViewerEvent::onLogCleared()`

- Name: `featherpanel:admin:log_viewer:cleared`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/LogViewerEvent.php#L36)

Docblock: string log type, string file name. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `log_type` | `$logType` | not declared |
| 2 | `log_file` | `$logFile` | `string` |
| 3 | `cleared_by` | `$clearedBy` | not declared |

When it fires (1 site)

-   [`LogViewerController::clearLogs`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/LogViewerController.php#L234)[`POST /api/admin/log-viewer/clear`](https://featherpanel.com/docs/api/reference/admin/log-viewer/#post-admin-log-viewer-clear)

```php
$event->on(LogViewerEvent::onLogCleared(), function ($logType, $logFile, $clearedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:log_viewer:cleared ' . json_encode(['log_file' => $logFile]));
});
```

## `LogViewerEvent::onLogViewerError()`

- Name: `featherpanel:admin:log_viewer:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/LogViewerEvent.php#L53)

Docblock: string error message, array context.

```php
$event->on(LogViewerEvent::onLogViewerError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:log_viewer:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `LogViewerEvent::onLogsUploaded()`

- Name: `featherpanel:admin:log_viewer:uploaded`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/LogViewerEvent.php#L44)

Docblock: array upload results. (the emitter passes 2 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `results` | `$results` | not declared |
| 2 | `uploaded_by` | `$uploadedBy` | not declared |

When it fires (1 site)

-   [`LogViewerController::uploadLogs`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/LogViewerController.php#L501)[`POST /api/admin/log-viewer/upload`](https://featherpanel.com/docs/api/reference/admin/log-viewer/#post-admin-log-viewer-upload)

```php
$event->on(LogViewerEvent::onLogsUploaded(), function ($results, $uploadedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:log_viewer:uploaded');
});
```

## `LogViewerEvent::onLogViewed()`

- Name: `featherpanel:admin:log_viewer:viewed`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/LogViewerEvent.php#L28)

Docblock: string log type, string file name.

```php
$event->on(LogViewerEvent::onLogViewed(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:log_viewer:viewed ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.
