Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
/ laravel-logviewer Public archive

View and filter your Laravel logs in the browser.

License

Notifications You must be signed in to change notification settings

Label84/laravel-logviewer

Repository files navigation

Warning

This package is no longer maintained.

We have decided to stop maintaining this package. We don't use this package anymore and don't have the time to maintain this package.

Feel free to fork our code and adapt it to your needs.

Laravel LogViewer

Latest Stable Version MIT Licensed Total Downloads GitHub Workflow Status

LogViewer enables you to view and filter your Laravel logs in the browser.

LogViewer screenshot

Laravel Support

Version Release
10.x ^3.0
9.x ^3.0
8.x ^2.1

Installation

1. Require package

Add the package to your application.

composer require label84/laravel-logviewer

You can also manually update your composer.json.

2. Publish config file

Add the config file to your application.

php artisan vendor:publish --provider="Label84\LogViewer\LogViewerServiceProvider" --tag="config"

2.1 Publish the views (optional)

To change the default views, you can publish the views to your application.

php artisan vendor:publish --provider="Label84\LogViewer\LogViewerServiceProvider" --tag="views"

Usage

Visit the following url in your application: /admin/logviewer

You can change the url in the config file.

Query filters

You can filter the logs in the overview with query parameters - example /admin/logviewer?date=today&message=kiss.

Parameter Value Example
level= string DEBUG
date= Carbon today
from= Carbon yesterday
till= Carbon 2021-01-01
logger= string local
message= string love

Settings

To use the package in your own Controllers you can use the following settings. If you use the default package features and views you probably won't need this.

1. Set channel

To dynamically set the channel:

use LogViewer;

LogViewer::setChannel(string $channel);

2. Set path

To dynamically set the path:

use LogViewer;

LogViewer::setPath(string $path);

3. Set file

To dynamically set the file:

use LogViewer;

LogViewer::setFile(string $file);

4. Available methods

The LogViewerCollection extends Illuminate\Support\Collection with the following methods:

  • whereLevel(int|string $level)
  • whereMinLevel(int|string $level)
  • whereMaxLevel(int|string $level)
  • whereDate(Carbon|string $date)
  • whereDateFrom(Carbon|string $date)
  • whereDateTill(Carbon|string $date)
  • whereDateBetween(Carbon|string $startDate, Carbon|string $startDate)
  • whereLogger(string|array $logger)
  • whereMessage(string|array $query)
  • whereNotMessage(string|array $query)
  • whereUser(int $user)

Examples

Example 1

List all logs.

use LogViewer;

public function index(Request $request): View
{
    $items = LogViewer::logs()->paginate(50);

    return view('dashboard', compact('items'));
}

Example 2

List all logs created today with a minimum level of ERROR.

use Label84\LogViewer\Support\LogViewerLevel;
use LogViewer;

public function index(Request $request): View
{
    $items = LogViewer::logs()
        ->whereDate(today())
        ->whereMinLevel(LogViewerLevel::ERROR)
        ->paginate(50);

    return view('dashboard', compact('items'));
}

Example 3

List all logs with a minium level of DEBUG that contains the words 'Foo' and/or 'Bar'.

use Label84\LogViewer\Support\LogViewerLevel;
use LogViewer;

public function index(Request $request): View
{
    $items = LogViewer::logs()
        ->whereLevel(LogViewerLevel::DEBUG)
        ->whereMessage(['Foo', 'Bar'])
        ->paginate(50);

    return view('dashboard', compact('items'));
}

Levels

Level
Emergency 600
Alert 550
Critical 500
Error 400
Warning 300
Notice 250
Info 200
Debug 100

Tests

composer analyse
composer test

License

MIT