Nova Log Viewer Package


May 3rd, 2022

Nova Log Viewer Package

Laravel Nova author David Hemphill released the Nova Log Viewer source code—a tool for viewing your application logs via the Nova UI:

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:

2 * Fetch the latest content for a log.
3 *
4 * @param \Laravel\Nova\Http\Requests\NovaRequest $request
5 * @return \Illuminate\Http\JsonResponse
6 */
7public function fetch(NovaRequest $request)
9 $request->validate(['lastLine' => ['numeric']]);
10 $logFile = new File($request->log);
11 $lines = $logFile->contentAfterLine($request->lastLine);
12 $lastLine = $request->lastLine + substr_count($lines, PHP_EOL);
14 return response()->json([
15 'lastLine' => $lastLine,
16 'content' => $lines,
17 'numberOfLines' => $logFile->numberOfLines(),
18 ]);

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:

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.