Nova Log Viewer Package | Laravel News
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
2 * Fetch the latest content for a log.
4 * @param LaravelNovaHttpRequestsNovaRequest $request
5 * @return IlluminateHttpJsonResponse
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(),
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 2002—here are some resources to get started with the latest version:
Credit: Source link