PHPackages                             sayidmuhammad/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. sayidmuhammad/laravel-telegram-logger

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

sayidmuhammad/laravel-telegram-logger
=====================================

Send Laravel logs to Telegram chat or topic via bot

v2.0.1(1mo ago)0166↓50%MITPHPPHP ^8.1

Since Nov 17Pushed 5mo agoCompare

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

READMEChangelogDependencies (10)Versions (6)Used By (0)

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

[](#laravel-telegram-logger)

[![Latest Version](https://camo.githubusercontent.com/67555c54f4c11bb70012fa2ef64df18de1ca1c91e7571dbb2ccd18e2ae0a0b08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73617969646d7568616d6d61642f6c61726176656c2d74656c656772616d2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sayidmuhammad/laravel-telegram-logger)[![License](https://camo.githubusercontent.com/cb77fca3b9d1729ba0319d50b35fbf9e2bc3456abe0e8b53fcf7d82a78c36028/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73617969646d7568616d6d61642f6c61726176656c2d74656c656772616d2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sayidmuhammad/laravel-telegram-logger)

Send Laravel logs to Telegram chat or topic via bot. This package integrates seamlessly with Laravel's logging system and allows you to receive log notifications directly in your Telegram chats or group topics.

Features
--------

[](#features)

- ✅ **Multiple log levels support** - Filter logs by level (debug, info, warning, error, etc.)
- ✅ **Topic support** - Send logs to specific topics in supergroups
- ✅ **Emoji indicators** - Visual indicators for different log levels
- ✅ **Context data formatting** - Beautiful formatting for context and extra data
- ✅ **Stack trace for errors** - Automatic stack trace inclusion for errors
- ✅ **Message length handling** - Automatic truncation for long messages
- ✅ **Retry mechanism** - Automatic retry on failed requests
- ✅ **Easy configuration** - Simple setup via config file or environment variables
- ✅ **Error handling** - Prevents infinite loops when Telegram API fails

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require sayidmuhammad/laravel-telegram-logger
```

Configuration
-------------

[](#configuration)

### 1. Create Telegram Bot

[](#1-create-telegram-bot)

1. Open Telegram and search for [@BotFather](https://t.me/BotFather)
2. Send `/newbot` command and follow the instructions
3. Copy the bot token you receive

### 2. Get Chat ID

[](#2-get-chat-id)

#### For Personal Chat:

[](#for-personal-chat)

1. Start a conversation with your bot
2. Send a message to your bot
3. Visit: `https://api.telegram.org/bot/getUpdates`
4. Find the `chat.id` value in the response

#### For Group/Supergroup:

[](#for-groupsupergroup)

1. Add your bot to the group
2. Make the bot an administrator (optional, but recommended)
3. Visit: `https://api.telegram.org/bot/getUpdates`
4. Find the `chat.id` value (it will be negative for groups)

#### For Topics (Supergroups with Topics):

[](#for-topics-supergroups-with-topics)

1. Create a topic in your supergroup
2. Send a message to the topic
3. Visit: `https://api.telegram.org/bot/getUpdates`
4. Find the `message_thread_id` value in the response

### 3. Environment Variables

[](#3-environment-variables)

Add the following to your `.env` file:

```
TELEGRAM_LOG_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
TELEGRAM_LOG_CHAT_ID=-1001234567890
TELEGRAM_LOG_TOPIC_ID=123
TELEGRAM_LOG_LEVEL=error
TELEGRAM_LOG_ENABLED=true
```

### 4. Publish Configuration (Optional)

[](#4-publish-configuration-optional)

If you want to customize the configuration, publish the config file:

```
php artisan vendor:publish --provider="SayidMuhammad\TelegramLogger\TelegramLoggerServiceProvider" --tag="telegram-logger-config"
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

Add the Telegram channel to your `config/logging.php`:

```
'channels' => [
    'telegram' => [
        'driver' => 'custom',
        'via' => SayidMuhammad\TelegramLogger\CreateTelegramLogger::class,
        'level' => env('TELEGRAM_LOG_LEVEL', 'error'),
    ],

    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'telegram'],
    ],
],
```

### Using the Logger

[](#using-the-logger)

#### Basic Usage

[](#basic-usage)

```
use Illuminate\Support\Facades\Log;

// Send error to Telegram
Log::error('Something went wrong!');

// Send critical error with context
Log::channel('telegram')->critical('Critical error!', [
    'user_id' => 123,
    'action' => 'payment',
    'amount' => 100.50,
]);
```

#### Using Specific Channel

[](#using-specific-channel)

```
// Send only to Telegram
Log::channel('telegram')->error('Error message');

// Send to both file and Telegram
Log::stack(['single', 'telegram'])->warning('Warning message');
```

#### With Exception

[](#with-exception)

```
try {
    // Your code
} catch (\Exception $e) {
    Log::channel('telegram')->error('Exception occurred', [
        'exception' => $e,
    ]);
}
```

Configuration Options
---------------------

[](#configuration-options)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefault`TELEGRAM_LOG_BOT_TOKEN`Telegram bot tokenRequired`TELEGRAM_LOG_CHAT_ID`Chat ID where logs will be sentRequired`TELEGRAM_LOG_TOPIC_ID`Topic ID (optional, for supergroups)`null``TELEGRAM_LOG_LEVEL`Minimum log level`error``TELEGRAM_LOG_ENABLED`Enable/disable logging`true`### Config File Options

[](#config-file-options)

```
return [
    // Bot configuration
    'bot_token' => env('TELEGRAM_LOG_BOT_TOKEN'),
    'chat_id' => env('TELEGRAM_LOG_CHAT_ID'),
    'topic_id' => env('TELEGRAM_LOG_TOPIC_ID'),

    // Logging configuration
    'level' => env('TELEGRAM_LOG_LEVEL', 'error'),
    'enabled' => env('TELEGRAM_LOG_ENABLED', true),

    // Formatting options
    'format' => [
        'include_date' => true,
        'include_level' => true,
        'include_context' => true,
        'include_trace' => true,
        'max_message_length' => 4096,
        'use_emojis' => true,
    ],

    // Emoji mapping
    'emojis' => [
        'debug' => '🐛',
        'info' => 'ℹ️',
        'notice' => '📢',
        'warning' => '⚠️',
        'error' => '❌',
        'critical' => '🔥',
        'alert' => '🚨',
        'emergency' => '💥',
    ],

    // Retry configuration
    'retry' => [
        'enabled' => true,
        'max_attempts' => 3,
        'delay' => 1000, // milliseconds
    ],

    // Request timeout
    'timeout' => 5, // seconds
];
```

Log Levels
----------

[](#log-levels)

The package supports all standard Monolog log levels:

- `debug` - Detailed debug information
- `info` - Informational messages
- `notice` - Normal but significant events
- `warning` - Warning messages
- `error` - Error messages
- `critical` - Critical conditions
- `alert` - Action must be taken immediately
- `emergency` - System is unusable

Message Format
--------------

[](#message-format)

Messages are formatted with HTML and include:

- **Emoji indicator** - Visual indicator for log level
- **Level name** - Uppercase log level name
- **Date and time** - When the log was created
- **Message** - The actual log message
- **Context** - Additional context data (if provided)
- **Stack trace** - For errors, critical, alert, and emergency levels

Example output:

```
❌ ERROR
📅 2024-01-15 10:30:45

Something went wrong!

Context:
{
    "user_id": 123,
    "action": "payment"
}

Stack Trace:
#0 /path/to/file.php:123
#1 /path/to/file.php:456

```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Configuration per Channel

[](#custom-configuration-per-channel)

You can create multiple Telegram channels with different configurations:

```
'channels' => [
    'telegram-errors' => [
        'driver' => 'custom',
        'via' => SayidMuhammad\TelegramLogger\CreateTelegramLogger::class,
        'level' => 'error',
        'bot_token' => env('TELEGRAM_ERROR_BOT_TOKEN'),
        'chat_id' => env('TELEGRAM_ERROR_CHAT_ID'),
    ],

    'telegram-warnings' => [
        'driver' => 'custom',
        'via' => SayidMuhammad\TelegramLogger\CreateTelegramLogger::class,
        'level' => 'warning',
        'bot_token' => env('TELEGRAM_WARNING_BOT_TOKEN'),
        'chat_id' => env('TELEGRAM_WARNING_CHAT_ID'),
    ],
],
```

### Disable Logging Temporarily

[](#disable-logging-temporarily)

```
// In your code
config(['telegram-logger.enabled' => false]);
Log::error('This won\'t be sent to Telegram');
config(['telegram-logger.enabled' => true]);
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Troubleshooting
---------------

[](#troubleshooting)

### Logs are not being sent

[](#logs-are-not-being-sent)

1. **Check configuration**: Ensure `TELEGRAM_LOG_BOT_TOKEN` and `TELEGRAM_LOG_CHAT_ID` are set correctly
2. **Check bot permissions**: Make sure the bot is added to the chat/group
3. **Check log level**: Verify the log level matches your configuration
4. **Check enabled status**: Ensure `TELEGRAM_LOG_ENABLED` is set to `true`
5. **Check Laravel logs**: Look for errors in `storage/logs/laravel.log`

### Bot token is invalid

[](#bot-token-is-invalid)

- Verify the token with BotFather
- Ensure there are no extra spaces in the token
- Check if the bot is still active

### Chat ID not working

[](#chat-id-not-working)

- For groups, ensure the chat ID is negative (starts with `-`)
- Make sure the bot is a member of the group
- For topics, verify the `message_thread_id` is correct

### Message too long

[](#message-too-long)

- The package automatically truncates messages longer than 4096 characters
- Adjust `max_message_length` in config if needed (but Telegram limit is 4096)

Security Considerations
-----------------------

[](#security-considerations)

- **Never commit your bot token** to version control
- Use environment variables for sensitive data
- Consider using different bots for different environments
- Regularly rotate your bot tokens

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Support
-------

[](#support)

For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/sayidmuhammad/laravel-telegram-logger).

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for a list of changes.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance78

Regular maintenance activity

Popularity15

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

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 ~30 days

Total

5

Last Release

54d ago

Major Versions

v1.2.0 → v2.0.02026-03-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e0bb5ab1aaccf1c8ca773c62e067ba79fde38613f4606be32ae957ba63b1c29?d=identicon)[sayidmuhammad\_jabborov](/maintainers/sayidmuhammad_jabborov)

---

Tags

laravelloggingloggertelegrammonolog

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[marvinlabs/laravel-discord-logger

Logging to a discord channel in Laravel

2081.1M2](/packages/marvinlabs-laravel-discord-logger)[thecoder/laravel-monolog-telegram

Telegram Handler for Monolog

2939.5k](/packages/thecoder-laravel-monolog-telegram)[naoray/laravel-github-monolog

Log driver to store logs as github issues

10619.4k](/packages/naoray-laravel-github-monolog)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)

PHPackages © 2026

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