PHPackages                             cesarbalzer/laravel-telegram-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cesarbalzer/laravel-telegram-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cesarbalzer/laravel-telegram-logger
===================================

Canal de log customizado para enviar mensagens de erro para o Telegram

v1.0.6(10mo ago)019MITPHPPHP ^8.2CI passing

Since Jul 10Pushed 8mo agoCompare

[ Source](https://github.com/CesarBalzer/laravel-telegram-logger)[ Packagist](https://packagist.org/packages/cesarbalzer/laravel-telegram-logger)[ RSS](/packages/cesarbalzer-laravel-telegram-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (9)Used By (0)

[![Packagist Version](https://camo.githubusercontent.com/9ca64b9011ebdae04e231ea6693653c9dfdcbd4379e7ff3e4ba0d8d1fcf0542e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/9ca64b9011ebdae04e231ea6693653c9dfdcbd4379e7ff3e4ba0d8d1fcf0542e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)[![Release Workflow](https://github.com/CesarBalzer/laravel-telegram-logger/actions/workflows/tag-release.yml/badge.svg)](https://github.com/CesarBalzer/laravel-telegram-logger/actions/workflows/tag-release.yml/badge.svg)[![License](https://camo.githubusercontent.com/4385bac89747aa4bf633016e527f9cb3a91458c77387ac217cdbc1d682b742d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/4385bac89747aa4bf633016e527f9cb3a91458c77387ac217cdbc1d682b742d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)[![PHP Version](https://camo.githubusercontent.com/347f3745518555fc999e4d858c83a12647044e9ff3c35671b74d3eeadf7190fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/347f3745518555fc999e4d858c83a12647044e9ff3c35671b74d3eeadf7190fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)[![Downloads](https://camo.githubusercontent.com/39c9241cfa91d8fc53e3d6e80bbc1fac4e99195d8a722986c6a82dae89cda510/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/39c9241cfa91d8fc53e3d6e80bbc1fac4e99195d8a722986c6a82dae89cda510/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636573617262616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)[![Last Commit](https://camo.githubusercontent.com/31cdd35f58ada6c5e0a4336b5c5ffabe5b1a45790af0968097da8de42296fb2e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/31cdd35f58ada6c5e0a4336b5c5ffabe5b1a45790af0968097da8de42296fb2e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)[![Issues](https://camo.githubusercontent.com/1b78250c9f3a8936207b9b530b1bb28b4b96dce4feec0e542ce266e67c582317/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)](https://camo.githubusercontent.com/1b78250c9f3a8936207b9b530b1bb28b4b96dce4feec0e542ce266e67c582317/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f436573617242616c7a65722f6c61726176656c2d74656c656772616d2d6c6f67676572)

Laravel Telegram Logger
=======================

[](#laravel-telegram-logger)

Este pacote permite que aplicações Laravel enviem **logs críticos (error, emergency, etc)** diretamente para um **grupo ou canal do Telegram** usando um bot. Ideal para monitorar falhas em produção em tempo real.

---

✅ Recursos
----------

[](#-recursos)

- Envio automático de erros via `Log::error()`, `Log::emergency()`, etc.
- Suporte a `.env` para configuração rápida.
- Ignora mensagens irrelevantes como 404 de scans.
- Integrado com o sistema de logging nativo do Laravel.

---

🧰 Instalação
------------

[](#-instalação)

```
composer require cesarbalzer/laravel-telegram-logger:@dev
```

Se estiver desenvolvendo localmente com um repositório path:

```
// composer.json
"repositories": [
  {
    "type": "path",
    "url": "./packages/cesarbalzer/laravel-telegram-logger"
  }
]
```

---

⚙️ Configuração
---------------

[](#️-configuração)

### 1. Adicione no `config/logging.php`:

[](#1-adicione-no-configloggingphp)

```
'channels' => [
    'telegram' => [
        'driver' => 'custom',
        'via' => CesarBalzer\TelegramLogger\Logger\TelegramLogger::class,
        'level' => env('LOG_TELEGRAM_LEVEL'),
    ],
],
```

### 2. Publique a configuração:

[](#2-publique-a-configuração)

```
php artisan vendor:publish --tag=telegram-logger-config
```

### 3. Configure seu `.env`:

[](#3-configure-seu-env)

```
TELEGRAM_BOT_TOKEN=seu_token_aqui
TELEGRAM_CHAT_ID=-1001234567890
TELEGRAM_LOG_LEVEL=error
```

---

> ⚠️ O `chat_id` de grupos começa com `-100` seguido dos dígitos do ID.

---

🤖 Como criar seu Bot no Telegram
--------------------------------

[](#-como-criar-seu-bot-no-telegram)

1. No Telegram, abra o `@BotFather`
2. Envie `/newbot` e siga as instruções
3. Copie o `BOT TOKEN` gerado (ex: `123456:ABCDEF...`)

---

💬 Como obter o `chat_id` do grupo
---------------------------------

[](#-como-obter-o-chat_id-do-grupo)

1. Crie um grupo no Telegram
2. Adicione o bot ao grupo
3. Envie qualquer mensagem no grupo
4. Acesse no navegador:

```
https://api.telegram.org/bot/getUpdates

```

5. Procure algo assim no JSON retornado:

```
"chat": {
  "id": -1001234567890,
  "title": "Nome do Grupo",
  ...
}
```

Use o `id` no `.env`.

---

🧪 Teste rápido
--------------

[](#-teste-rápido)

Você pode testar com uma rota simples ou criar alguns testes forçados:

```
Route::get('/error', function () {
    // ✅ Log informativo - não vai para o Telegram
    Log::info('HttpRequest GET 200 /home', [
        'method' => 'GET',
        'endpoint' => '/home',
        'status' => 200,
        'ip' => request()->ip(),
    ]);

    // 🚫 Log ignorado por palavra-chave (não será enviado ao Telegram)
    Log::error('HttpRequest GET 404 sitemap.xml', [
        'method' => 'GET',
        'endpoint' => 'sitemap.xml',
        'status' => 404,
        'ip' => request()->ip(),
    ]);

    // ✅ Log de erro real - será enviado ao Telegram
    Log::error('🚨 Erro crítico no processamento do pagamento', [
        'user_id' => 999,
        'order_id' => 12345,
        'status' => 'failed',
    ]);

    // ✅ Simulando exceção capturada
    try {
        throw new \Exception("Erro de teste proposital em /error");
    } catch (\Throwable $e) {
        Log::error("🚨 Exceção capturada em /error: " . $e->getMessage(), [
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            // Não incluí o trace para não sujar o Telegram
        ]);
    }

    return 'Logs enviados! Verifique o Telegram e o storage/logs/laravel.log';
});

Route::get('/telegram', function () {
    // ✅ Teste direto no canal Telegram
    Log::channel('telegram')->error('🚨 Log de teste no canal Telegram', [
        'user_id' => 999,
        'ip' => request()->ip(),
        'time' => now()->toDateTimeString(),
    ]);

    return 'Log enviado!';
});
```

---

📄 Licença
---------

[](#-licença)

MIT © [Cesar Balzer](https://github.com/cesarbalzer)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance58

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

306d ago

Major Versions

v0.0.1 → v1.0.12025-07-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa93814e4f2ca4bbfba8a024272970b15df90e4d332cbc12d2f6b938c86294c6?d=identicon)[CesarBalzer](/maintainers/CesarBalzer)

---

Top Contributors

[![CesarBalzer](https://avatars.githubusercontent.com/u/13343041?v=4)](https://github.com/CesarBalzer "CesarBalzer (1 commits)")

### Embed Badge

![Health badge](/badges/cesarbalzer-laravel-telegram-logger/health.svg)

```
[![Health](https://phpackages.com/badges/cesarbalzer-laravel-telegram-logger/health.svg)](https://phpackages.com/packages/cesarbalzer-laravel-telegram-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
