Activity Logs Plugin

The Activity Logs plugin provides comprehensive activity tracking and logging functionality for your application. It automatically logs various system events including authentication, requests, responses, exceptions, and custom activities. All logs are processed asynchronously through a queue system for optimal performance.

Features

Automatic Activity Tracking

The plugin automatically tracks various system events:

  • Authentication events: Sign in, sign out, sign in errors
  • Request and response logging: All HTTP requests and responses
  • Exception and error tracking: Captures exceptions and errors
  • Data Grid Store (DGS) operations: Tracks DGS-related activities

Activity Categories

Activities are organized into the following categories:

  • General activities: General system activities
  • Authentication events: User authentication-related events
  • Exceptions and errors: System exceptions and errors
  • DGS operations: Data Grid Store operations

Activity Types

Each activity can be classified by type:

  • Success events: Successful operations
  • Error events: Failed operations or errors
  • Loading events: Operations in progress

Priority Levels

Activities can be assigned priority levels:

  • Low priority: Non-critical activities
  • Medium priority: Standard activities
  • High priority: Critical activities requiring attention

Automatic Data Collection

The plugin automatically collects the following data for each activity:

  • User ID: Automatically captured if user is authenticated
  • IP address: Client IP address
  • User agent: Browser/client user agent string
  • Current URL: The URL where the activity occurred
  • Timestamp: Automatic timestamp of when the activity occurred

Asynchronous Processing

  • Queue-based logging: All logs are processed through a queue system for optimal performance
  • Non-blocking activity recording: Activity recording doesn't block the main application flow

Management Interface

  • View and filter activity logs: Browse and search through all activity logs
  • Accessible at: /manage/activity/logs/

Usage

Creating Custom Activity Logs

To create custom activity logs in your code, use the plugin's facade:

<?php

use plugin\ActivityLogs\domain\model\ActivityLogValuesObject;

$activityLogsPlugin = Core::getInstance()->getPluginInstance('ActivityLogs');

$activityLogValuesObject = new ActivityLogValuesObject();
$activityLogValuesObject->setCategory(ActivityLogValuesObject::CATEGORY_GENERAL);
$activityLogValuesObject->setAction('custom_action');
$activityLogValuesObject->setType(ActivityLogValuesObject::TYPE_SUCCESS);
$activityLogValuesObject->setPriority(ActivityLogValuesObject::PRIORITY_MEDIUM);
$activityLogValuesObject->setNote('Custom activity description');
$activityLogValuesObject->setContext(json_encode(['additional' => 'data']));

$activityLogsPlugin->createQueue($activityLogValuesObject);

Available Categories

ActivityLogValuesObject::CATEGORY_GENERAL        // General activities
ActivityLogValuesObject::CATEGORY_AUTHENTICATION // Authentication events
ActivityLogValuesObject::CATEGORY_EXCEPTION      // Exceptions and errors
ActivityLogValuesObject::CATEGORY_DGS            // Data Grid Store operations

Available Types

ActivityLogValuesObject::TYPE_SUCCESS  // Successful operations
ActivityLogValuesObject::TYPE_ERROR    // Error events
ActivityLogValuesObject::TYPE_LOADING  // Loading/processing events

Available Priorities

ActivityLogValuesObject::PRIORITY_LOW    // Low priority events
ActivityLogValuesObject::PRIORITY_MEDIUM // Medium priority events
ActivityLogValuesObject::PRIORITY_HIGH  // High priority events

Activity Log Fields

The following fields are available for activity logs:

  • id_user - User ID (automatically set if user is authenticated)
  • type - Activity type (success, error, loading)
  • category - Activity category (general, authentication, exception, dgs)
  • priority - Priority level (low, medium, high)
  • action - Action identifier
  • cdate - Creation date (automatically set)
  • url - Current URL (automatically set)
  • ip - IP address (automatically set)
  • note - Additional notes or description
  • context - JSON-encoded context data
  • useragent - User agent string (automatically set)

Management Interface

Access the activity logs management interface at:

/manage/activity/logs/

This interface allows you to: - View all activity logs - Filter logs by various criteria - Search through activity history - Review system activity patterns

Events

BeforeLoadActivityLogsEvent

When you need to preventively customize active log store parameters before it loads, you can use this event. For example: through this event, you are able to set your filters for the store.

Example of appliance through event listener in init.php into your plugin directory:

<?php

$this->addEventListener(
    BeforeLoadActivityLogsEvent::TYPE,
    function (BeforeLoadActivityLogsEvent &$event) {
        $store = $event->getStore();

        $filters = &$store->getModel()->getFilters();
        $filters['your_filter_name'] = $yourFilterValue;
    }
);

BeforeCreateQueueEvent

This event is dispatched before an activity log is added to the queue, allowing you to modify the activity log data before it's processed.

<?php

use plugin\ActivityLogs\domain\event\BeforeCreateQueueEvent;

$this->addEventListener(
    BeforeCreateQueueEvent::EVENT_BEFORE_CREATE_QUEUE,
    function (BeforeCreateQueueEvent &$event) {
        $activityLogValuesObject = $event->getTargetValueByKey('activityLogValuesObject');

        // Modify the activity log before it's queued
        $activityLogValuesObject->setNote('Modified note');
    }
);