{"id":21889286,"url":"https://github.com/jacklul/monolog-telegram","last_synced_at":"2025-07-16T08:11:58.475Z","repository":{"id":56995447,"uuid":"122515069","full_name":"jacklul/monolog-telegram","owner":"jacklul","description":"Monolog handler that sends logs through Telegram bot to any chat in HTML format","archived":false,"fork":false,"pushed_at":"2025-01-24T18:09:17.000Z","size":201,"stargazers_count":23,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-22T08:51:29.430Z","etag":null,"topics":["monolog","monolog-handler","telegram"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacklul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-22T18:01:01.000Z","updated_at":"2025-05-10T17:15:35.000Z","dependencies_parsed_at":"2025-03-02T10:10:38.052Z","dependency_job_id":"25c7711f-ebe3-47e6-95b6-004a0a519b73","html_url":"https://github.com/jacklul/monolog-telegram","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":"0.045454545454545414","last_synced_commit":"ec8674fbd280bbb369b5f48447259e44a92f39c8"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/jacklul/monolog-telegram","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklul%2Fmonolog-telegram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklul%2Fmonolog-telegram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklul%2Fmonolog-telegram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklul%2Fmonolog-telegram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacklul","download_url":"https://codeload.github.com/jacklul/monolog-telegram/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacklul%2Fmonolog-telegram/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265495610,"owners_count":23776652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["monolog","monolog-handler","telegram"],"created_at":"2024-11-28T11:23:37.187Z","updated_at":"2025-07-16T08:11:58.458Z","avatar_url":"https://github.com/jacklul.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monolog Telegram Handler\n\nSend your logs through Telegram bot to any chat and make them look fancy!\n\n#### Features:\n- [Continous logging](https://i.imgur.com/8EnxO90.jpg) and [batch logging](https://i.imgur.com/4C9Y6cT.jpg) support\n- Standard stack traces wrapped in `\u003ccode\u003e\u003c/code\u003e` tags\n- Automatic splitting of the message when it exceeds maximum limit\n\n## Prerequisites\n\n - Telegram Bot API token - [see here](https://core.telegram.org/bots#creating-a-new-bot) to learn how to obtain one\n - ID of the chat to which you want to send the logs - see below\n\n#### Obtaining chat ID\n\nOne of the simplest ways to do that is to interact with the bot in the target chat:\n- private and group chats - send any dummy command\n- channels - post something in it\n\nAfter interacting visit `https://api.telegram.org/botTOKEN/getUpdates` (replace `TOKEN` with your actual bot token), you will be able to find the chat id (`chat_id`) in the result JSON.\n\n## Installation\n\nInstall with [Composer](https://github.com/composer/composer):\n\n```bash\n$ composer require jacklul/monolog-telegram\n```\n\n## Usage\n\nTo use this handler you just have to add it like every other **Monolog** handler:\n\n```php\nrequire 'vendor/autoload.php';\n\n$logger = new Logger('My project');\n$handler = new TelegramHandler(\n    '123456789:teMbvbETojnSG93jDhnynvH8pT28H9TIB1h',  // Bot API token\n    987654321,  // Target Chat ID\n    Logger::ERROR,  // Log level, default: DEBUG\n    true,  // Bubble up the stack or not, default: true\n    true,  // Use cURL or not? default: true = use when available\n    10,    // Timeout for API requests, default: 10\n    true   // Verify SSL certificate or not? default: true, false only useful for development - avoid in production\n    2,     // (optional) Target Thread ID for group chats with Topics enabled\n);\n\n$handler-\u003esetFormatter(new TelegramFormatter());    // Usage of this formatter is optional but recommended if you want better message layout\n$logger-\u003epushHandler($handler);\n\n$logger-\u003eerror('Error!');\n```\n\nTo prevent spamming the chat and hitting Telegram's API limits it is advised to use\n [DeduplicationHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/DeduplicationHandler.php) and/or [BufferHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/BufferHandler.php), ideal solution for production use would be:\n\n```php\n$handler = new TelegramHandler('TOKEN', 123456789);\n$handler-\u003esetFormatter(new TelegramFormatter());\n\n// Combine all log entries into one and force batch processing\n$handler = new BufferHandler($handler);\n\n// Make sure that particular log stack wasn't sent before\n$handler = new DeduplicationHandler($handler);\n\n// Keep collecting logs until ERROR occurs, after that send collected logs to $handler\n$handler = new FingersCrossedHandler($handler, new ErrorLevelActivationStrategy(Logger::ERROR));\n\n$logger-\u003epushHandler($handler);\n```\n\nYou can customize the formatter:\n\n```php\n$html = true;    // Choose whether to send the message in HTMl format\n$format = \"%emoji% \u003cb\u003e%level_name%\u003c/b\u003e (%channel%) [%date%]\\n\\n%message%\\n\\n%context%%extra%\";   // EMOJI ERROR (My project) [2018-05-01 15:55:15 UTC]\n$date_format = 'Y-m-d H:i:s e';       // 2018-05-01 15:55:15 UTC, format must be supported by DateTime::format\n$separator = '-';       // Seperation character for batch processing - when empty one empty line is used\n$emojis = [         // Override any level emoji\n    'NOTICE' =\u003e '🤖'\n];\n\n$handler-\u003esetFormatter(new TelegramFormatter($html, $format, $date_format, $separator, $emojis));\n```\n\n## Running tests\n\nCreate `.env` file:\n```\nTELEGRAM_TOKEN=BOT_TOKEN\nTELEGRAM_CHAT_ID=CHAT_ID_THE_BOT_WILL_SPAM;\n```\n\nRun `composer check-code` and `composer test`.\n\n## License\n\nSee [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklul%2Fmonolog-telegram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacklul%2Fmonolog-telegram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacklul%2Fmonolog-telegram/lists"}