monolog-mysql icon indicating copy to clipboard operation
monolog-mysql copied to clipboard

Laravel 5.6

Open renatosistemasvc opened this issue 7 years ago • 3 comments

when will be supported for laravel 5.6

I tried to install and gave error

renatosistemasvc avatar Feb 09 '18 14:02 renatosistemasvc

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 avatar Apr 21 '18 12:04 ilumos

@ilumos you saved my date!

mineschan avatar Jun 22 '18 08:06 mineschan

Here's an even simpler way of doing it with laravel and lumen from version 5.6 up to 7.x

  1. composer require wazaari/monolog-mysql
  2. 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',
            ],
        ]

8ctopus avatar May 12 '20 09:05 8ctopus