Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Setting Up a Log Viewer in Hyperf with Routing and View Components

Setting Up a Log Viewer in Hyperf with Routing and View Components

This guide explains how to install and configure the Hyperf log‑viewer component, publish its configuration, register a route, add view and template engine support, and adjust view and log settings to enable file log browsing and simple search within a PHP backend application.

1. Interface

The article begins with a screenshot illustrating the appearance of the log‑viewer page.

2. Usage

Step 1: Install the log‑viewer component. composer require sett/hyperf-log-viewer Step 2: Publish the component’s configuration file. php bin/hyperf.php vendor:publish sett/hyperf-log-viewer Step 3: Register a route that points to the viewer controller.

Router::get('/logs', 'Sett\LogViewer\Controller\LogViewController@index');

Step 4: Install the Hyperf view component. composer require hyperf/view Step 5: Install a template engine (think‑template). composer require sy-records/think-template Step 6: Configure the view settings in config/autoload/view.php (create the file if it does not exist).

return [
    'engine' => ThinkEngine::class,
    'mode'   => Mode::TASK,
    'config' => [
        // create these directories if they are missing
        'view_path'  => BASE_PATH . '/storage/view/',
        'cache_path' => BASE_PATH . '/runtime/view/',
    ],
];

Step 7: Add the log directory configuration in config/autoload/logViewer.php.

return [
    "path"    => BASE_PATH . "/runtime/logs/",
    "pattern" => "*.log",
    "size"    => 10,
];

3. Notes

The log timestamps must follow the YYYY-MM-DD HH:MM:SS format; otherwise records may not be displayed.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
BackendroutingPHPHyperfLog ViewerView Engine

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion