2017-25 © Pedro Peláez
 

library monolog-discord-handler

A simple Monolog handler for Discord webhooks

image

miraris/monolog-discord-handler

A simple Monolog handler for Discord webhooks

  • Sunday, April 1, 2018
  • by miraris
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 5 Versions
  • 67 % Grown

The README.md

monolog-discord-handler

Packagist Packagist, (*1)

A simple Monolog handler for Discord webhooks, (*2)


Dependecies

  • PHP >= 5.3
  • Monolog >= 1.3

1. Installing

The recommended way to install monolog-discord-handler is through Composer., (*3)

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of monolog-discord-handler:, (*4)

php composer.phar require miraris/monolog-discord-handler

After installing, you need to require Composer's autoloader:, (*5)

require 'vendor/autoload.php';

You can then later update monolog-discord-handler using composer:, (*6)

bash composer.phar update, (*7)


2. Usage

Push this handler to your Monolog instance:, (*8)

Single webhook URL

<?php
require 'vendor/autoload.php';

$log = new Monolog\Logger('name');

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

Multiple webhook URLs

<?php
require 'vendor/autoload.php';

$log = new Monolog\Logger('name');

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

Laravel

If you'd like to use this in Laravel, you need to create a custom logging channel inside config/logging.php assuming you're using Laravel 5.6., (*9)

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

Afterwards create the App\Logging\CreateDiscordLogger class., (*10)

<?php

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;
    }
}

This package has no built-in rate limiting so it's recommended to set the log level to ~warning/error to avoid exceeding the rate limit., (*11)

The Versions

01/04 2018

dev-master

9999999-dev

A simple Monolog handler for Discord webhooks

  Sources   Download

MIT

The Requires

 

by Avatar miraris

01/04 2018

0.2.0

0.2.0.0

A simple Monolog handler Discord webhooks

  Sources   Download

MIT

The Requires

 

by Avatar miraris

23/08 2017

0.1.2

0.1.2.0

A simple discord monolog for support Discord webhooks

  Sources   Download

MIT

The Requires

 

by Matthieu Bessat

23/08 2017

0.1

0.1.0.0

A simple discord monolog for support Discord webhooks

  Sources   Download

MIT

The Requires

 

by Matthieu Bessat

23/08 2017

0.1.1

0.1.1.0

A simple discord monolog for support Discord webhooks

  Sources   Download

MIT

The Requires

 

by Matthieu Bessat