marvinlabs/laravel-discord-logger
Composer 安装命令:
composer require marvinlabs/laravel-discord-logger
包简介
Logging to a discord channel in Laravel
README 文档
README
marvinlabs/laravel-discord-logger is a laravel package providing a logging handler to send logs to a Discord channel.
Installation
You can install the package via composer:
composer require marvinlabs/laravel-discord-logger
If you are using Laravel 5.5 or later, the service provider will automatically be discovered.
On earlier versions, you need to do that manually. You must install the service provider:
// config/app.php 'providers' => [ ... MarvinLabs\DiscordLogger\ServiceProvider::class ];
You can then publish the configuration file:
php artisan vendor:publish --provider "MarvinLabs\DiscordLogger\ServiceProvider"
Setup
Prepare the discord channel web hook
Create a discord web hook for the channel which will receive the logs.
Prepare the logger configuration
You must add a new channel to your config/logging.php file:
// config/logging.php 'channels' => [ //... 'discord' => [ 'driver' => 'custom', 'via' => MarvinLabs\DiscordLogger\Logger::class, 'level' => 'debug', 'url' => env('LOG_DISCORD_WEBHOOK_URL'), 'ignore_exceptions' => env('LOG_DISCORD_IGNORE_EXCEPTIONS', false), ], ];
You can then provide the web-hook URL in your .env file:
LOG_DISCORD_WEBHOOK_URL=https://discordapp.com/api/webhooks/abcd/1234
Use the logger channel
You have two options: log only to discord or add the channel to the stack
Log only to the discord channel
Simply change the .env variable to use the discord channel
LOG_CHANNEL=discord
Add the channel on top of other channels
Add the channel to the stack in the config/logging.php configuration:
// config/logging.php 'channels' => [ //... 'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'discord'], ], ];
Then make sure the logging channel is set to stack in your .env file:
LOG_CHANNEL=stack
Logging to multiple Discord channels
Of course, you can send your log messages to multiple Discord channels. Just create as many channels as desired in
config/logging.php and put them in the stack. Each channel should be named differently and should point to a different
web hook URL.
What does it look like?
You can get a preview of what it looks like using each of the provided converters.
The communication with Discord Web hook failed
You might encounter this exception alongside "cURL error 60: SSL certificate problem: unable to get local issuer certificate" while using/testing your web hook in a development enviroment. This occurs due to your local machine's inability to verify the server's SSL certificate.
To resolve this issue, follow these steps:
-
Obtain the cacert.pem file from the curl website.
-
Store the cacert.pem file in a secure location on your computer, such as C:\xampp\php\extras\ssl\cacert.pem.
-
Access your php.ini file, typically found in your PHP installation directory.
-
Locate curl.cainfo = in php.ini. If it's commented out (begins with a ;), remove the semicolon.
-
Insert the path to cacert.pem you saved earlier. Example: curl.cainfo = "C:\xampp\php\extras\ssl\cacert.pem".
-
Save the php.ini file and restart your server to implement the changes.
Version history
See the dedicated change log
Credits
- Got some ideas from GrKamil/laravel-telegram-logging
- Got some ideas from lefuturiste/monolog-discord-handler
License
The MIT License (MIT). Please see License File for more information.
marvinlabs/laravel-discord-logger 适用场景与选型建议
marvinlabs/laravel-discord-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.24M 次下载、GitHub Stars 达 208, 最近一次更新时间为 2019 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「logger」 「laravel」 「discord」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marvinlabs/laravel-discord-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marvinlabs/laravel-discord-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marvinlabs/laravel-discord-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Workflow logger
HTTP request logger middleware for Laravel
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
统计信息
- 总下载量: 1.24M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 209
- 点击次数: 30
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-29
