Download the PHP package nwservices/laravel-telegram-logger without Composer
On this page you can find all versions of the php package nwservices/laravel-telegram-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nwservices/laravel-telegram-logger
More information about nwservices/laravel-telegram-logger
Files in nwservices/laravel-telegram-logger
Package laravel-telegram-logger
Short Description A Laravel package that monitors laravel.log and sends Telegram notifications when errors occur
License MIT
Informations about the package laravel-telegram-logger
Laravel Telegram Logger
A Laravel package that monitors your laravel.log file and sends Telegram notifications when errors occur. Get instant alerts in your Telegram chat when critical errors happen in your Laravel application.
Features
- Monitors
storage/logs/laravel.logfor new errors - Scheduled task runs via Laravel scheduler (e.g., every minute)
- Only alerts on NEW errors (tracks file position to avoid duplicates)
- Configurable log levels (ERROR, CRITICAL, ALERT, EMERGENCY)
- Environment-based notifications (only send in production/staging)
- Rate limiting to prevent spam from duplicate errors
- Formatted messages with emojis for quick visual identification
- Handles multi-line log entries (stack traces)
- Detects log rotation automatically
Requirements
- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x
Installation
Install the package via Composer:
The service provider will be automatically registered through Laravel's package auto-discovery.
Publish the configuration file (optional):
Getting a Telegram Bot Token
- Open Telegram and search for @BotFather
- Start a conversation and send
/newbot - Follow the prompts to name your bot
- BotFather will provide you with a token like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz - Save this token for your environment configuration
Getting Your Chat ID
For Personal Notifications
- Search for @userinfobot on Telegram
- Start a conversation with it
- It will reply with your user ID (a number like
123456789)
For Group Notifications
- Add your bot to the group
- Send a message in the group
- Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for the
chatobject and find theidfield (it will be negative for groups, like-123456789)
For Channel Notifications
- Add your bot as an administrator to the channel
- Use the channel's username with an
@prefix (e.g.,@mychannel) - Or use the channel ID (find it using the getUpdates method after posting)
Configuration
Add these environment variables to your .env file:
Setting Up the Scheduler
The package provides an artisan command that monitors your log file. You need to schedule it to run periodically.
Laravel 11+ (routes/console.php)
Laravel 10 (app/Console/Kernel.php)
Make sure your server's cron is set up to run Laravel's scheduler:
Artisan Command
Basic Usage
Command Options
| Option | Description |
|---|---|
--log-path |
Path to log file (default: storage/logs/laravel.log) |
--levels |
Comma-separated log levels to monitor (default: from config) |
--dry-run |
Parse and display errors without sending to Telegram |
--reset |
Reset the file position tracker |
Configuration Options
| Option | Default | Description |
|---|---|---|
bot_token |
'' |
Your Telegram bot token from BotFather |
chat_id |
'' |
The Telegram chat/group/channel ID to send messages to |
project_name |
APP_NAME |
Project name displayed in notifications |
environment |
APP_ENV |
Environment name displayed in notifications |
notify_environments |
['production', 'staging'] |
Only send notifications in these environments |
throttle |
60 |
Seconds to wait before sending duplicate messages |
log_path |
storage/logs/laravel.log |
Path to the log file to monitor |
monitor_levels |
ERROR,CRITICAL,ALERT,EMERGENCY |
Log levels to monitor |
position_storage |
cache |
Where to store file position (cache or file) |
How It Works
- The
telegram:monitor-logcommand runs on a schedule (e.g., every minute) - It reads
laravel.logfrom the last saved position - Parses new content for log entries matching configured levels (e.g.,
.ERROR) - Sends Telegram notifications for each matching entry
- Saves the new file position to avoid re-processing
- Automatically detects log rotation and resets position
Log Level Emojis
Messages are prefixed with emojis for quick visual identification:
| Level | Emoji |
|---|---|
| Emergency | đ |
| Alert | đ |
| Critical | đ´ |
| Error | đ¨ |
| Warning | â ī¸ |
| Notice | đ |
| Info | âšī¸ |
| Debug | đ |
Example Message
Testing
To test if your configuration is working:
Security
- Never commit your bot token to version control
- Use environment variables for all sensitive configuration
- Consider using a dedicated bot for each project
- Be mindful of what information appears in your logs
License
The MIT License (MIT). Please see License File for more information.