PHP code example of thedomeffm / monolog-discord-handler-bundle

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

    

thedomeffm / monolog-discord-handler-bundle example snippets


// ...
use Monolog\LogRecord;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use TheDomeFfm\MonologDiscordHandlerBundle\Message\DiscordMessage;
use TheDomeFfm\MonologDiscordHandlerBundle\Message\DiscordMessageFactoryInterface;
use TheDomeFfm\MonologDiscordHandlerBundle\Message\Syntax;
use TheDomeFfm\MonologDiscordHandlerBundle\Message\Text;

#[AsDecorator(decorates: 'thedomeffm_monolog_discord_message_factory')]
class CustomMessageFactory implements DiscordMessageFactoryInterface
{
    public function createFromLogRecord(LogRecord $record): DiscordMessage
    {
        $message = new DiscordMessage();

        $message->append('# :x: Ohh noo an error!\n');
        $message->append(Text::create(Syntax::Code, $record->message)->render());

        return $message;
    }
}