wp-simple-logger

Log Viewer Guide

The built-in Log Viewer provides a user-friendly interface within the WordPress admin dashboard to browse, search, and manage logs stored by the Database_Handler.

Enabling the Log Viewer

The Log Viewer is a feature of the Database_Handler and is disabled by default. To enable it, you must call the set_admin_viewer() method when configuring your handler.

global $wpdb;
use WPTechnix\WP_Simple_Logger\Handlers\Database_Handler;

// Instantiate the handler
$db_handler = new Database_Handler(
    table_name: $wpdb->prefix . 'app_logs'
);

// Enable and configure the admin UI
$db_handler->set_admin_viewer(
    parent_menu_slug: 'tools.php',     // Show under the "Tools" menu
    page_slug:        'app-log-viewer', // Unique page slug
    page_title:       'Application Logs', // <title> and <h1> of the page
    menu_title:       'App Logs',       // Text in the admin menu
    capability:       'manage_options'  // Required capability to view
);

// Add the handler to the manager and initialize
$manager->add_handler($db_handler);
$manager->init();

Once configured, a new submenu item (“App Logs”) will appear under the “Tools” menu in the WordPress admin.

Features

The Log Viewer is a powerful tool for inspecting your application’s activity. It is built using the standard WP_List_Table class, providing a familiar WordPress experience.

Log Viewer Table Interface

1. Filtering

You can narrow down the log entries using the filter controls at the top of the table:

2. Searching

The search box allows you to perform a case-insensitive search through the message and context fields of the logs.

3. Sorting and Pagination

4. Context Viewer

If a log record includes context data, a “View Context” button will appear next to the message.

5. Bulk and Single Actions