itelmenko / laravel-mysql-logger
Laravel MySQL driver for Monolog
Installs: 117 778
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 10
Open Issues: 0
Requires
- php: >=8.1.0
- laravel/framework: ^10.0|^11.0
This package is auto-updated.
Last update: 2025-03-11 06:40:51 UTC
README
This package will log errors into MySQL database instead storage/log/laravel.log
file.
Installation
composer require itelmenko/laravel-mysql-logger
For Laravel earlier than 10.0, please use version 1.0.7 of this package.:
composer require itelmenko/laravel-mysql-logger:v1.0.7
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,
);
In config/logging.php
<?php // [...] 'channels' => [ // [...] 'mysql' => [ 'driver' => 'custom', 'via' => ITelmenko\Logger\Laravel\Logging\MySQLLogger::class, 'connection' => env('DB_LOG_CONNECTION'), 'table' => env('DB_LOG_TABLE'), 'name' => 'my.channel' // optional ], ],
Publish config using Laravel Artisan CLI.
php artisan vendor:publish
and select the option Provider: ITelmenko\Logger\Laravel\Providers\MonologMysqlHandlerServiceProvider
Migrate tables.
php artisan migrate
Add ITelmenko\Logger\Laravel\Exceptions\MysqlLoggerInsertException
into your ExceptionHandler
to prevent looping when a database connection fails:
public function register()
{
$this->reportable(function (Throwable $e) {
if ($this->shouldReport($e) && app()->bound('sentry')) {
app('sentry')->captureException($e);
}
if ($e instanceof MysqlLoggerInsertException) {
return false; // prevent looping
}
});
}
Using
Somewhere in your application
Log::channel('mysql')->info('Something happened!');
TODO
Change$table->bigIncrements('id')
to something like ULIDChange root namespace toITelmenko
Removeextra
fields from modelRemove 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