jeff/lara-logger

Add logs in your laravel project in database

v0.0.2 2024-12-01 17:09 UTC

This package is auto-updated.

Last update: 2025-06-30 03:29:17 UTC


README

LaraLogger is a Laravel package that provides a custom logging solution to store log entries directly in a database. This package includes a ready-to-use DatabaseLogger channel and provides necessary migrations to set up a logs table.

Features

  • Custom Log Channel: Store logs in the database using a dedicated channel.
  • Database Migration: Automatic setup for a logs table.
  • Configurable: Easily integrate into your existing Laravel logging configuration.

Installation

  1. Install the package using Composer:
composer require jeff/lara-logger
  1. Add Jeff\LaraLogger\Providers\LoggingServiceProvider::class to providers list (/bootstrap/providers.php):
<?php

return [
    ...,
    Jeff\LaraLogger\Providers\LoggingServiceProvider::class,
];
  1. Run the Publish command (optional):
php artisan vendor:publish --provider="Jeff\LaraLogger\Providers\LoggingServiceProvider"
  1. Run the migrations to create the logs table:
php artisan migrate
  1. Add the following logging-related environment variables to your .env file if needed:
LOG_CHANNEL=database
LOG_STACK=custom

Usage

  1. Add Logs:
\Illuminate\Support\Facades\Log::info('test ok');
\Illuminate\Support\Facades\Log::info('test ok', [
... ,
'test' => 'tests'
]);
\Illuminate\Support\Facades\Log::error('test ok');
\Illuminate\Support\Facades\Log::warning('test ok');
\Illuminate\Support\Facades\Log::channel('database')->info('test ok');
  1. List Logs, (ex: in a route function):
return \Jeff\LaraLogger\App\Models\LogModel::all(['*']);