All Projects → merorafael → monolog-telegram-handler

merorafael / monolog-telegram-handler

Licence: MIT license
Monolog handler to send log by Telegram

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to monolog-telegram-handler

Alice
Painless middleware chaining for Go
Stars: ✭ 2,438 (+7518.75%)
Mutual labels:  handler
logger
A Monolog-based logging tool for WordPress. Supports storing log message in a custom post type or in individual posts and terms.
Stars: ✭ 20 (-37.5%)
Mutual labels:  monolog
slim-skeleton
Slim Framework skeleton application following MVC construction
Stars: ✭ 18 (-43.75%)
Mutual labels:  monolog
app
Buggregator is a beautiful, lightweight debug server build on Laravel that helps you catch your smpt, sentry, var-dump, monolog, ray outputs. It runs without installation on multiple platforms.
Stars: ✭ 259 (+709.38%)
Mutual labels:  monolog
monolog-http
A collection of monolog handlers that use a PSR-18 HTTP Client to send your logs
Stars: ✭ 34 (+6.25%)
Mutual labels:  monolog
Easy Log Handler
Human-friendly log files that make you more productive
Stars: ✭ 2,070 (+6368.75%)
Mutual labels:  monolog
Xcrash
🔥 xCrash provides the Android app with the ability to capture java crash, native crash and ANR. No root permission or any system permissions are required.
Stars: ✭ 2,689 (+8303.13%)
Mutual labels:  handler
defense
🔮 A Crystal HTTP handler for throttling, blocking and tracking malicious requests.
Stars: ✭ 51 (+59.38%)
Mutual labels:  handler
enlite-monolog
Monolog integration to Laminas
Stars: ✭ 17 (-46.87%)
Mutual labels:  monolog
monolog-gdpr
Some Monolog processors that help with GDPR compliance
Stars: ✭ 49 (+53.13%)
Mutual labels:  monolog
monolog-google-cloud-json-formatter
A Monolog extension for formatting log entries for Google Cloud Logging
Stars: ✭ 15 (-53.12%)
Mutual labels:  monolog
monolog-sentry-handler
Monolog handler for Sentry PHP SDK v2 with breadcrumbs support
Stars: ✭ 34 (+6.25%)
Mutual labels:  monolog
Monolog Bundle
Symfony Monolog Bundle
Stars: ✭ 2,532 (+7812.5%)
Mutual labels:  monolog
codeigniter-monolog-plus
codeigniter monolog plus
Stars: ✭ 13 (-59.37%)
Mutual labels:  monolog
HandlerFrame
🐮 HandlerFrame是一个基于观察者模式采用信息分发机制实现跨界面Handler通讯框架,整个项目里面只存在一个Handler实例对象。
Stars: ✭ 42 (+31.25%)
Mutual labels:  handler
Middleware
Community Middleware List for the Iris Web Framework.
Stars: ✭ 188 (+487.5%)
Mutual labels:  handler
Monolog Bridge
Provides integration for Monolog with various Symfony components.
Stars: ✭ 2,238 (+6893.75%)
Mutual labels:  monolog
JYSort
Android 图形化排序, 六种类排序算法可视化展示
Stars: ✭ 15 (-53.12%)
Mutual labels:  handler
laravel-log-mailer
A package to support logging via email in Laravel
Stars: ✭ 14 (-56.25%)
Mutual labels:  monolog
yii2-monolog
Yii 2 Monolog extension
Stars: ✭ 39 (+21.88%)
Mutual labels:  monolog

TelegramHandler

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License

Monolog handler to send log by Telegram.

Requirements

  • PHP 5.6 or above
  • cURL extension

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/telegram-handler to add TelegramHandler in your project vendor;
  3. Add symfony/yaml dependency if you need use the \Mero\Monolog\Formatter\HtmlFormatter.

Declaring handler object

To declare this handler, you need to know the bot token and the chat identifier(chat_id) to which the log will be sent.

// ...
$handler = new \Mero\Monolog\Handler\TelegramHandler('<token>', <chat_id>, <log_level>);
// ...

Example:

<?php

$log = new \Monolog\Logger('telegram_channel');

$handler = new \Mero\Monolog\Handler\TelegramHandler(
    '000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    111111111,
    \Monolog\Logger::DEBUG
);
$handler->setFormatter(new \Mero\Monolog\Formatter\HtmlFormatter());
$handler->setTimeout(30);
$log->pushHandler($handler);

$log->debug('Message log');

The above example is using HtmlFormatter for Telegram API. This feature is added on 0.3.0 release and you can use declaring handler formatter to use \Mero\Monolog\Formatter\HtmlFormatter class.

You can set the timeout for Telegram request using setTimeout method, implemented on TelegramHandler. This feature is implemented on 0.4.0 release and this use is not required.

Creating a bot

To use this handler, you need to create your bot on telegram and receive the Bot API access token. To do this, start a conversation with @BotFather.

Conversation example:

In the example below, I'm talking to @BotFather. to create a bot named "Cronus Bot" with user "@cronus_bot".

Me: /newbot
---
@BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.
---
Me: Cronus Bot
---
@BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: 
TetrisBot or tetris_bot.
---
Me: cronus_bot
---
@BotFather: Done! Congratulations on your new bot. You will find it at telegram.me/cronus_bot. You can now add a 
description, about section and profile picture for your bot, see /help for a list of commands. By the way, when 
you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure 
the bot is fully operational before you do this.

Use this token to access the HTTP API:
000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

Give a chat identifier

To retrieve the chat_id in which the log will be sent, the recipient user will first need a conversation with the bot. After the conversation has started, make the request below to know the chat_id of that conversation.

URL: https://api.telegram.org/bot_token_/getUpdates

Example:

Request
-------
POST https://api.telegram.org/bot000000000:XXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates

Response
--------
{
  "ok": true,
  "result": [
    {
      "update_id": 141444845,
      "message": {
        "message_id": 111,
        "from": {
          "id": 111111111,
          "first_name": "Rafael",
          "last_name": "Mello",
          "username": "merorafael"
        },
        "chat": {
          "id": 111111111,
          "first_name": "Rafael",
          "last_name": "Mello",
          "username": "merorafael",
          "type": "private"
        },
        "date": 1480701504,
        "text": "test"
      }
    }
  ]
}

In the above request, the chat_id is represented by the number "111111111".

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].