Backend Development 3 min read

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.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Setting Up a Log Viewer in Hyperf with Routing and View Components

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).

<code>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/',
    ],
];</code>

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

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

3. Notes

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

backendRoutingPHPHyperfLog ViewerView Engine
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.