jackmartin / telegram-logger-errors
Telegram 日志错误包 laravel
1.8
2022-10-04 09:13 UTC
Requires
- php: ^7.0 || ^7.2 || ^7.3
- illuminate/support: ^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- irazasyed/telegram-bot-sdk: ^3.0
This package is auto-updated.
Last update: 2024-09-04 13:21:53 UTC
README
Telegram 日志错误
laravel TLE 包 - Telegram 错误日志器
要求
- php 7.0
- composer
安装
使用 composer 安装包
composer require jackmartin/telegram-logger-errors
Laravel 配置
通过 composer 安装包后,在 config/app.php 文件中注册服务包
Telegram\Bot\Laravel\TelegramServiceProvider::class, TLE\TLEServiceProvider::class
然后为了快速调用包中的类,在同一文件中添加别名
'Telegram' => Telegram\Bot\Laravel\Facades\Telegram::class, 'TLE' => TLE\Facades\TLEFacade::class
将配置文件 telegram.php,tle.php 复制到 config 文件夹
Telegram SDK
php artisan vendor:publish
选择 Provider:Telegram\Bot\Laravel\TelegramServiceProvider
TLE
php artisan vendor:publish
选择 Tag:tle-config
或者
php artisan vendor:publish --provider="TLE\TLEServiceProvider" --tag="tle-config"
在 config/telegram.php 中设置令牌和机器人名称
'bots' => [ 'common' => [ 'username' => 'Name bot', 'token' => 'Token bot', 'commands' => [], ], ], 'default' => 'common',
调试模式
'debug' => false
机器人名称
用于 Telegram SDK
'botname' => ''
聊天标识符
'chat_id' => ''
保存日志
'save_log' => true
临时文件保存路径
'path_save' => 'local'
禁用将 Telegram 错误记录到日志文件
'disable_exception_telegram' => false
用法
发送简单异常
use TLE; try { print_r($a); } catch (\Exception $e) { TLE::exp($e)->send(); }
发送简单异常 + 信息
use TLE; try { print_r($a); } catch (\Exception $e) { TLE::exp($e)->info('Field check')->send(); }
发送 Guzzle 异常
use TLE; try { print_r($a); } catch (RequestException $e) { TLE::guzzle($e)->send(); }
在 app/Exceptions/Handler.php 中添加 TLE 类到全局错误处理器
public function report(Exception $exception) { \TLE::exp($exception)->send(); parent::report($exception); }