Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.6 #2

Open
renatosistemasvc opened this issue Feb 9, 2018 · 3 comments
Open

Laravel 5.6 #2

renatosistemasvc opened this issue Feb 9, 2018 · 3 comments

Comments

@renatosistemasvc
Copy link

when will be supported for laravel 5.6

I tried to install and gave error

@ilumos
Copy link
Contributor

ilumos commented Apr 21, 2018

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/

@mineschan
Copy link

@ilumos you saved my date!

@8ctopus
Copy link

8ctopus commented May 12, 2020

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',
            ],
        ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants