monolog-mysql
monolog-mysql copied to clipboard
Laravel 5.6
when will be supported for laravel 5.6
I tried to install and gave error
You can use https://github.com/Gilg4mesh/monolog-mysql along with the new way of registering loggers in Laravel 5.6:
config/logging.php
<?php
// [...]
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['mysql'],
],
// [...]
'mysql' => [
'driver' => 'custom',
'via' => App\Logging\CreateMySQLLogger::class,
],
],
app/Logging/CreateMySQLLogger.php
<?php
namespace App\Logging;
use Exception;
use Monolog\Logger;
use Logger\Monolog\Handler\MysqlHandler;
class CreateMySQLLogger
{
/**
* Create a custom Monolog instance.
*
* @param array $config
* @return Logger
* @throws Exception
*/
public function __invoke(array $config)
{
$channel = $config['name'] ?? env('APP_ENV');
$monolog = new Logger($channel);
$monolog->pushHandler(new MysqlHandler());
return $monolog;
}
}
Further reading: https://blog.bugsnag.com/laravel-5-6/
@ilumos you saved my date!
Here's an even simpler way of doing it with laravel and lumen from version 5.6 up to 7.x
- composer require wazaari/monolog-mysql
- Edit file config/logging.php as follows
<?php
use MySQLHandler\MySQLHandler;
...
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'mysql'],
],
...
'mysql' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => MySQLHandler::class,
'with' => [
'pdo' => app('db')->connection()->getPdo(),
'table' => 'table-name',
],
]