Laravel Log Reader

Laravel Log Reader

Logs are very important to audit the application state. The laravel framework gives the facility out of the box but laravel log files are not easy to read and by default, there is no facility to view the logs from the application. The laravel log reader package gives you the facility to view your all laravel log files with a fresh UI. You can view logs date by date and filter with log types and clearing logs so easy.

Features of Laravel Log Reader

  • Clean and fresh looking UI
  • Date by date log viewing
  • Filtering logs
  • Clearing logs
  • Configurable route
  • Responsive design
  • JSON API available

 

Installation

composer require haruncpi/laravel-log-reader

Installation is done! Yah it's a really simple process. Now you are ready to use Laravel Log Reader.

Just browse the http://example.com/admin/log-reader . You must be authenticated to view the logs.

log-reader-desktop.png

Make sure your log channel set for daily 'channels' => ['daily'] in config/logging.php 

 

Customizations

 

1. JSON API [OPTIONAL]

If you want to make your won UI then this package also provides the JSON API for log files. You will get the API link here /admin/api/log-reader

API response example

{
  "success": true,
  "data": {
    "available_log_dates": [
      "2020-01-27"
    ],
    "date": "2020-01-27",
    "filename": "laravel-2020-01-27.log",
    "logs": [
      {
        "timestamp": "2020-01-27 12:26:45",
        "env": "local",
        "type": "INFO",
        "message": "Backup success"
      },
      {
        "timestamp": "2020-01-27 12:26:45",
        "env": "local",
        "type": "EMERGENCY",
        "message": "Backup failed"
      }
    ]
  }
}

Get JSON data by date

use Haruncpi\LaravelLogReader\LaravelLogReader;

return (new LaravelLogReader(['date' => '2020-01-27']))->get();

 

2. Config file [OPTIONAL]

If you want to change the route URL for viewing the logs then run the command for publishing laravel log reader configuration file.

php artisan vendor:publish --provider="Haruncpi\LaravelLogReader\ServiceProvider" --tag="config"

 

Need More Restrictions?

If you need more restriction to view logs, override the routes in your route file with your custom middleware or any logic you need.

Route::group([
    'namespace' => '\Haruncpi\LaravelLogReader\Controllers',
    'middleware' => ['auth','middleware1','middleware2']
    ],
    function () {
        Route::get(config('laravel-log-reader.view_route_path'), 'LogReaderController@getIndex');
        Route::post(config('laravel-log-reader.view_route_path'), 'LogReaderController@postDelete');
        Route::get(config('laravel-log-reader.api_route_path'), 'LogReaderController@getLogs');
    }
);

 

Hope the Laravel Log Reader package will help you to read, manage your Laravel log files easily! If this package helpful for you then please share the post with others.

 

Share on

Related Post


DB Seeder - A database seeder application

Laravel Simple Filemanager

Laravel Option Framework

Laravel Simple Captcha

Laravel Livewire - run php like javascript!

Laravel Sanctum - API authentication