https://github.com/sergeymakinen/yii2-telegram-log
Telegram log target for Yii 2
https://github.com/sergeymakinen/yii2-telegram-log
log logging logging-library notification notifications php php-library telegram yii2 yii2-extension
Last synced: 6 months ago
JSON representation
Telegram log target for Yii 2
- Host: GitHub
- URL: https://github.com/sergeymakinen/yii2-telegram-log
- Owner: sergeymakinen
- License: mit
- Archived: true
- Created: 2017-01-05T15:22:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-01-24T19:43:35.000Z (over 4 years ago)
- Last Synced: 2025-01-12T10:40:01.462Z (6 months ago)
- Topics: log, logging, logging-library, notification, notifications, php, php-library, telegram, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 579 KB
- Stars: 26
- Watchers: 8
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Telegram log target for Yii 2
[Telegram](https://telegram.org) log target for Yii 2.

[](https://scrutinizer-ci.com/g/sergeymakinen/yii2-telegram-log) [](https://travis-ci.org/sergeymakinen/yii2-telegram-log) [](https://codecov.io/gh/sergeymakinen/yii2-telegram-log) [](https://insight.sensiolabs.com/projects/8b4f3236-7c78-42d1-8355-54605598d941)
[](https://packagist.org/packages/sergeymakinen/yii2-telegram-log) [](https://packagist.org/packages/sergeymakinen/yii2-telegram-log) [](LICENSE)
## Installation
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Either run
```bash
composer require "sergeymakinen/yii2-telegram-log:^2.0"
```or add
```json
"sergeymakinen/yii2-telegram-log": "^2.0"
```to the require section of your `composer.json` file.
## Usage
First [create a new bot](https://core.telegram.org/bots#6-botfather) and obtain its token. It should look like `123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11`.
You will also need a [chat ID](https://stackoverflow.com/questions/31078710/how-to-obtain-telegram-chat-id-for-a-specific-user) to send logs to. You can use the [`@get_id_bot`](https://telegram.me/get_id_bot) bot to obtain it. It should look like `123456789`.
Then set the following Yii 2 configuration parameters:
```php
'components' => [
'log' => [
'targets' => [
[
'class' => 'sergeymakinen\yii\telegramlog\Target',
'token' => '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
'chatId' => 123456789,
],
],
],
],
```## Configuration
By default `yii\log\Logger` error levels are mapped to emojis (you can tweak them in the `levelEmojis` property):
| Error level | Emoji
| --- | ---
`Logger::LEVEL_ERROR` | ☠️
`Logger::LEVEL_WARNING` | ⚠️
`Logger::LEVEL_INFO` | ℹ️
`Logger::LEVEL_TRACE` | 📝It's also possible to disable notifications - entirely or per logger level (look at the `enableNotification` property), for example:
```php
public $enableNotification = [
Logger::LEVEL_ERROR => true,
Logger::LEVEL_WARNING => false,
Logger::LEVEL_INFO => false,
];
```This will disable notifications for warning and info level messages and enable them for other levels (honestly, you can omit the `LEVEL_ERROR` definition here as it's `true` by default).