Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/markhilton/monolog-mysql

Laravel 5 log to MySQL database
https://github.com/markhilton/monolog-mysql

Last synced: 22 days ago
JSON representation

Laravel 5 log to MySQL database

Awesome Lists containing this project

README

        

## Laravel Monolog MySQL Handler.

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

### Installation

```sh
composer require markhilton/monolog-mysql
```

Open up `config/app.php` and find the `providers` key.

```php
'providers' => array(
// ...
Logger\Laravel\Provider\MonologMysqlHandlerServiceProvider::class,
);
```

Publish config using Laravel Artisan CLI.

```sh
php artisan vendor:publish
```

Migrate tables - you may want to [configure enviornment](#environment-configuration) beforehand.

```sh
php artisan migrate
```

## Application Integration

In your application `config/logging.php` add:

```php
use Logger\Monolog\Handler\MysqlHandler;

// ...

'channels' => [
// ...
'mysql' => [
'driver' => 'monolog',
'handler' => MysqlHandler::class,
'level' => 'debug',
],
];
```

# Application Integration (Laravel >= 5.6)

In your application `config/logging.php` add:

```php
[
'stack' => [
'driver' => 'stack',
'channels' => ['mysql'],
],
// [...]
'mysql' => [
'driver' => 'custom',
'via' => App\Logging\CreateMySQLLogger::class,
],
],
```

In your application `app/Logging/CreateMySQLLogger.php` add:

```php
pushHandler(new MysqlHandler());
return $monolog;
}
}
```

## Environment configuration

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

```env
DB_LOG_TABLE=logs
DB_LOG_CONNECTION=mysql
```

## Credits

Based on:

- [Pedro Fornaza] (https://github.com/pedrofornaza/monolog-mysql)