PHP code example of miraris / monolog-discord-handler

1. Go to this page and download the library: Download miraris/monolog-discord-handler 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/ */

    

miraris / monolog-discord-handler example snippets





 = new Monolog\Logger('name');

$log->pushHandler(new DiscordHandler\DiscordHandler([
    'https://discordapp.com/api/webhooks/xxx/yyy'
], 'DEBUG'));



 = new Monolog\Logger('name');

$log->pushHandler(new DiscordHandler\DiscordHandler([
    'https://discordapp.com/api/webhooks/xxx/yyy',
    'https://discordapp.com/api/webhooks/xxx/yyy',
], 'DEBUG'));


'channels' => [
    'custom' => [
        'driver' => 'custom',
        'url' => 'https://discordapp.com/api/webhooks/xxx/yyy',
        'via' => App\Logging\CreateDiscordLogger::class,
        'level' => 'error',
    ],
],



namespace App\Logging;

use Monolog\Logger;
use DiscordHandler\DiscordHandler;

class CreateDiscordLogger
{
    /**
     * Create a custom Discord Monolog instance.
     *
     * @param  array  $config
     * @return \Monolog\Logger
     */
    public function __invoke(array $config)
    {
        $log = new Logger('mylogger');
        $log->pushHandler(new DiscordHandler([$config['url']], $config['level']));

        return $log;
    }
}
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php