dyanakiev/laravel-logger-discord-channel

基于 Discord 的 Laravel Monolog 驱动器

6.1.1 2024-08-14 12:23 UTC

This package is auto-updated.

Last update: 2024-09-14 12:34:24 UTC


README

基于 Discord 的 Laravel Monolog 驱动器

Latest Stable Version Total Downloads Daily Downloads Latest Unstable Version License PHP Version Require

安装

composer require dyanakiev/laravel-logger-discord-channel

用法

  1. 在您的 config/logging.php 配置文件中添加新的 Discord 通道类型,找到通道部分并在其中添加 Discord 数组
'channels' => [
        'discord' => [
            'driver' => 'custom',
            'via' => dyanakiev\LoggerDiscordChannel\DiscordLogger::class,
            'suffix' => env('DISCORD_LOG_SUFFIX','Laravel Log'), // Message title suffix
            'webhook' => env('DISCORD_LOG_WEBHOOK', false), // e.g. https://discordapp.com/api/webhooks/...
            'level' => env('DISCORD_LOG_LEVEL', 'debug'), // You can choose from: emergency, alert, critical, error, warning, notice, info and debug
            'context' => env('DISCORD_LOG_CONTEXT', false), // Enable this if you want to receive the full context of an error, usually useless
            'environment' => env('DISCORD_LOG_ENVIRONMENT', 'production'), // Enable logging only for environment ['production', 'staging', 'local']
            'message' => env('DISCORD_LOG_MESSAGE', false), // Here you can put extra message or tag role or person via @personName
        ],
],
  1. stack 通道内添加新的 Discord 通道,建议将 LOG_CHANNEL 设置为 stack,这样您在运行生产环境时仍能保留日常日志
  2. 直接在配置中或在 .env 文件中自定义包设置

注意

如果您在安装后遇到 laravel.EMERGENCY: Unable to create configured logger. ... Log [discord] is not defined. 错误,可能需要清除缓存

php artisan config:clear

别忘了在清除缓存后在生产环境中再次缓存配置 :)

php artisan config:cache

示例日志

demo-error-imessage demo-info-imessage