Skip to content

A Monolog Handler to send your logs to discord using webhooks

License

Notifications You must be signed in to change notification settings

bobvmierlo/monolog-discord-handler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monolog discord handler

Latest Stable Version Total Downloads License Monthly Downloads

A simple monolog handler for support Discord webhooks


Dependencies

  • PHP >= 7.2
  • Monolog >= 1.3

If you want to use this lib with older version of PHP than 7.2, install versions prior to 0.3


1. Installing

Easy installation via composer. Still no idea what composer is? Find out here here.

composer require lefuturiste/monolog-discord-handler


2. Usage

Push this handler to your Monolog instance:

Single webhook URL

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

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

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

Multiple webhook URLs

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

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

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

Use configuration

You can customize the default message and datetime format.

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

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

$handler = new DiscordHandler\DiscordHandler('https://discordapp.com/api/webhooks/xxx/yyy', 'name', 'subname', 'DEBUG');

$handler->getConfig()
    ->setMultiMsg(true)
    ->setMaxMessageLength(2000) // at least 50 characters
    ->setDatetimeFormat('Y/m/d H:i')
    ->setTemplate("{datetime} {name}: {message}");

// or you can create another Config instance and replace it:
$otherConfig = new DiscordHandler\Config();
$otherConfig->setWebHooks([
  'https://discordapp.com/api/webhooks/xxx/yyy', 
  'https://discordapp.com/api/webhooks/xxx/yyy'
]);

$handler->setConfig($otherConfig);

$log->pushHandler($handler);

About

A Monolog Handler to send your logs to discord using webhooks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%