Skip to content

Enaah/laravel-mysql-logger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Monolog MySQL Handler.

This package will log errors into MySQL database instead storage/log/laravel.log file.

Installation

composer require itelmenko/laravel-mysql-logger

If you wish to change default table name to write the log into or database connection use following definitions in your .env file

DB_LOG_TABLE=logs
DB_LOG_CONNECTION=mysql

For Laravel < 5.5 open up config/app.php and find the providers key.

'providers' => array(
    // ...
    ITelmenko\Logger\Laravel\Providers\MonologMysqlHandlerServiceProvider::class,
);

Publish config using Laravel Artisan CLI.

php artisan vendor:publish

Migrate tables.

php artisan migrate

Using

In config/logging.php

<?php
    // [...]

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['mysql'],
        ],

        // [...]

        'mysql' => [
            'driver' => 'custom',
            'via' => ITelmenko\Logger\Laravel\Logging\MySQLLogger::class,
            'connection' => env('DB_LOG_CONNECTION'),
            'table' => env('DB_LOG_TABLE'),
            'name' => 'my.channel' // optional
        ],
    ],

Somewhere in your application

Log::channel('mysql')->info('Something happened!');

TODO

  • Change $table->bigIncrements('id') to something like ULID
  • Change root namespace to ITelmenko
  • Remove extra fields from model
  • Remove updated_at?
  • Add microseconds for created_at
  • Update version and readme.md (about a changing of migration, about vendor:publish)
  • Add php doc
  • Add phpcs

About

Laravel 5.6+ MySQL driver for Monolog

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%