Nova Log Viewer Package
Published on by Paul Redmond
Laravel Nova author David Hemphill released the Nova Log Viewer source code—a tool for viewing your application logs via the Nova UI:
🚀 Just released the source to our Nova Log Viewer tool. Install it to view your application logs or use the source as an example to create your own tool: https://t.co/enWIFVmgII 🖤
— HEMP (@davidhemphill) May 2, 2022
The UI allows you to select which log file to view and even supports polling. Further, you can use the source code to see how these tools integrate with Nova and use it as a starting point to build your own.
While looking through the source code, I found a couple of gems (to me), such as defining an invokable controller and using the same controller to define another method for the API call to get logs.
The fetch API controller method shows off a neat instance method I've not used before called contentAfterLine
:
/** * Fetch the latest content for a log. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @return \Illuminate\Http\JsonResponse */public function fetch(NovaRequest $request){ $request->validate(['lastLine' => ['numeric']]); $logFile = new File($request->log); $lines = $logFile->contentAfterLine($request->lastLine); $lastLine = $request->lastLine + substr_count($lines, PHP_EOL); return response()->json([ 'lastLine' => $lastLine, 'content' => $lines, 'numberOfLines' => $logFile->numberOfLines(), ]);}
Learn More
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
Laravel Nova v4 was released in April 2022—here are some resources to get started with the latest version: