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-viewerStep 2: Publish the component’s configuration file.
php bin/hyperf.php vendor:publish sett/hyperf-log-viewerStep 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/viewStep 5: Install a template engine (think‑template).
composer require sy-records/think-templateStep 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.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.