stepanenko3 / nova-logs-tool

A Laravel Nova tool to manage and keep track of each one of your logs files.
MIT License
26 stars 11 forks source link

Displaying latest log messages on a Nova dashboard (possible documentation addition?) #9

Closed johnpuddephatt closed 2 years ago

johnpuddephatt commented 2 years ago

I was looking into displaying log messages on my Nova dashboard using the new Table metric introduced in V4.

I took a look at how this package gets data from logs and realised I could piggyback off it very easily!

Below is all that was needed to display the latest three lines from laravel.log (this is from the 'calculate' method of my table metric)

        $lines = array_slice(Stepanenko3\LogsTool\LogsService::all("laravel.log"), 0, 3);
        foreach ($lines as $line) {
            $rows[] = MetricTableRow::make()
                ->icon(
                    $line["level_img"]
                )
                ->iconClass(
                    $line["level_class"]
                )
                ->title($line["text"])
                ->subtitle(
                    \Carbon\Carbon::create($line["date"])->diffForHumans()
                );
        }
        return $rows;

and here's the result:

Screenshot 2022-07-25 at 10 58 35

stepanenko3 commented 2 years ago

@johnpuddephatt, thank you so much for your idea

I'll write it down to README a little later Or you can open PR

stepanenko3 commented 2 years ago

@johnpuddephatt, I added it to README

Thanks for the idea