PHP code example of markhilton / monolog-mysql

1. Go to this page and download the library: Download markhilton/monolog-mysql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

markhilton / monolog-mysql example snippets


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

use Logger\Monolog\Handler\MysqlHandler;

// ...

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


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


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;
    }
}
sh
php artisan vendor:publish
sh
php artisan migrate