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

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

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

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.