承接 codelikesuraj/lograh-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codelikesuraj/lograh-php

最新稳定版本:v1.0.0

Composer 安装命令:

composer require codelikesuraj/lograh-php

包简介

A light-weight logger that logs to Telegram.

README 文档

README

LograhPHP sends your exceptions to Telegram chats, channels or groups.

Requirements

  • PHP 8.0 or above.
  • php_curl extension enabled.
  • A Telegram bot's access token and chat/channel/group id. Generate a Telegram bot with https://telegram.me/BotFather.

Installation

$ composer require codelikesuraj/lograh-php

Basic Usage

Sample code

<?php

use Codelikesuraj\LograhPHP\Logger;

// initialize logger with your Telegram bot credentials
$logger = new Logger(
    appName: "unique_name_to_identify_your_app",
    botToken: "api_key_generated_from_your_telegram_bot",
    chatId: "id_of_your_telegram_chat_or_channel_or_group"
);

try {
    // code that may generate an exception
    ...
} catch (\Throwable $exception) {
    // optional list of exceptions to be ignored
    $logger->ignore([ExceptionA::class, ExceptionB::class]);
    
    // send exception to Telegram using any
    // of the following methods
    $logger->reportAsText($exception);
    $logger->reportAsJson($exception);
    $logger->reportAsJsonWithStackTrace($exception);
    
    // further processing
    ...
}

Sample response message sent to Telegram

Report as TEXT

app: unique_name_to_identify_your_app
timestamp: 0000-00-00 00:00:00 +0000
"summary": Uncaught exception: 'exception_name' with message 'exception_message' in /path/to/folder/file.php:#

Report as JSON

{
    "app": "unique_name_to_identify_your_app",
    "timestamp": "0000-00-00 00:00:00 +0000",
    "summary": "Uncaught exception: 'exception_name' with message 'exception_message' in \/path\/to\/folder\/file.php:#",
}

Report as JSON WITH STACK TRACE

{
    "app": "unique_name_to_identify_your_app",
    "timestamp": "0000-00-00 00:00:00 +0000",
    "summary": "Uncaught exception: 'exception_name' with message 'exception_message' in \/path\/to\/folder\/file.php:#",
    "stack trace": [
        "#0 {main}"
    ]
}

Author

Abdulbaki Suraj - http://twitter.com/fliplikesuraj

License

LograhPHP is licensed under the MIT License.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-15