PHPackages                             saasscaleup/laravel-log-alarm - 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. saasscaleup/laravel-log-alarm

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

saasscaleup/laravel-log-alarm
=============================

Laravel log Alarm help you to set up alarm when errors occur in your system and send you a notification via Slack and email

v1.0.6(1y ago)27025.0k—8.7%17[4 PRs](https://github.com/saasscaleup/laravel-log-alarm/pulls)MITPHP

Since Jun 20Pushed 1y ago3 watchersCompare

[ Source](https://github.com/saasscaleup/laravel-log-alarm)[ Packagist](https://packagist.org/packages/saasscaleup/laravel-log-alarm)[ Docs](https://github.com/saasscaleup/laravel-log-alarm)[ Fund](https://buymeacoffee.com/scaleupsaas)[ GitHub Sponsors](https://github.com/saasscaleup)[ RSS](/packages/saasscaleup-laravel-log-alarm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

[![Main Window two](https://github.com/saasscaleup/laravel-log-alarm/raw/master/lla-saasscaleup.png?raw=true)](https://github.com/saasscaleup/laravel-log-alarm/blob/master/lla-saasscaleup.png?raw=true)

Real-time Log Monitoring and Error Detection for Your Laravel Applications
==========================================================================

[](#real-time-log-monitoring-and-error-detection-for-your-laravel-applications)

####  [Youtube](https://youtube.com/@ScaleUpSaaS)  ·  [Twitter](https://twitter.com/ScaleUpSaaS)  ·  [Facebook](https://facebook.com/ScaleUpSaaS)  ·  [Buy Me a Coffee](https://buymeacoffee.com/scaleupsaas)

[](#--youtube------twitter------facebook------buy-me-a-coffee)

 [ ![Latest Stable Version](https://camo.githubusercontent.com/39cbc6b869cda7090fe86e6a2b767fa3e5bd4c3f408fc235d2e7b95373b3450d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736161737363616c6575702f6c61726176656c2d6c6f672d616c61726d2e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/saasscaleup/laravel-log-alarm) [ ![Total Downloads](https://camo.githubusercontent.com/35d8867e9ba0591c0c7b08fd3d01dc03a92051083514b973cf21ad1f67213130/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736161737363616c6575702f6c61726176656c2d6c6f672d616c61726d2e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/saasscaleup/laravel-log-alarm) [ ![License](https://camo.githubusercontent.com/7453ad21fff778760a06d84bc08f06b2052e87c5ef0c72fa8f782b7b0955094b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736161737363616c6575702f6c61726176656c2d6c6f672d616c61726d2e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/saasscaleup/laravel-log-alarm)

Log Alarm for Laravel
=====================

[](#log-alarm-for-laravel)

**Log Alarm** is a robust and easy-to-use Laravel package designed to enhance your application's logging capabilities. Whether you're running a small web app or a large enterprise system, Log Alarm helps you stay on top of your logs by providing real-time monitoring, error detection, and instant notifications via Slack and email.

✨ Features
----------

[](#-features)

- **Real-time Log Monitoring**: Continuously listen for log events and keep track of your application's health.
- **Error Detection**: Automatically detect and respond to error log events.
- **Customizable Notifications**: Send instant notifications to Slack and email when errors occur.
- **Frequency Control**: Set thresholds and delays to avoid notification flooding.
- **Cache-based Alert System**: Efficiently track error occurrences without the overhead of database operations.
- **Flexible Configuration**: Easily configure settings and specify error conditions with custom strings.

Why Choose Log Alarm?
---------------------

[](#why-choose-log-alarm)

In today's fast-paced digital environment, timely responses to application issues are crucial. Log Alarm ensures that you and your team are promptly informed about critical errors, reducing downtime and improving your application's reliability. Perfect for developers, system administrators, and DevOps teams looking to enhance their monitoring capabilities.

Requirements
------------

[](#requirements)

- PHP &gt;= 7
- Laravel &gt;= 5

⬇️ Installation
---------------

[](#️-installation)

Install the package via Composer:

```
composer require saasscaleup/laravel-log-alarm
```

#### For Laravel &lt; 5.5

[](#for-laravel--55)

Add Service Provider to `config/app.php` in `providers` section

```
Saasscaleup\LogAlarm\LogAlarmServiceProvider::class,
```

---

### Publish package's config file

[](#publish-packages-config-file)

Publish package's config, migration and view files by running below command:

```
php artisan vendor:publish --provider="Saasscaleup\LogAlarm\LogAlarmServiceProvider"
```

Usage
-----

[](#usage)

The package will automatically start listening to your application's log events. Customize the settings in the `config/log-alarm.php` file to match your requirements. For Example:

```
LA_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url
LA_NOTIFICATION_EMAIL=your-email@example.com
LA_NOTIFICATION_EMAIL_SUBJECT="Log Alarm Notification"

```

In order to trigger the Log Alarm with the current defualt setting, All you need to do is

1. Add your `LA_SLACK_WEBHOOK_URL` and `LA_NOTIFICATION_EMAIL`
2. Print Error log 5 times in `tinker` or in your `Controller`

Telegram Notification Configuration
-----------------------------------

[](#telegram-notification-configuration)

Add `LA_TELEGRAM_BOT_TOKEN` and `LA_TELEGRAM_CHAT_ID` to your `.env`

### Getting a Bot Token:

[](#getting-a-bot-token)

1. Open Telegram and search for `@BotFather`
2. Start a chat with BotFather and send `/newbot`
3. Follow the prompts:

- Provide a name for your bot
- Provide a username for your bot (must end in 'bot'). Example: `MyTelegramBot` or `my_telegram_bot`

4. BotFather will give you a bot token that looks like this: `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`

### Getting the Chat ID:

[](#getting-the-chat-id)

#### Method 1 (For Direct Messages):

[](#method-1-for-direct-messages)

1. Start a chat with your new bot
2. Send it any message
3. Visit this URL in your browser (replace with your bot token):

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

```

4. Look for the "chat" -&gt; "id" field in the JSON response. It will be a number like `123456789`.

```
"chat": {
    "id": 123456789,
},
```

#### Method 2 (For Groups):

[](#method-2-for-groups)

1. Add your bot to the group
2. Send a message in the group
3. Use the same /getUpdates URL method above
4. Look for "chat" -&gt; "id" in the response. For groups, it will be a negative number like -123456789

#### Important Tips:

[](#important-tips)

Keep your bot token secret - anyone with it can control your bot For groups, make sure to give the bot permission to read messages If you don't see any updates in the /getUpdates response, send a new message to the bot or group The chat ID is permanent for that chat or group unless the bot is removed and re-added

### Tinker example:

[](#tinker-example)

```
php artisan tinker

```

```
\Log::error('Log alarm');
\Log::error('Log alarm');
\Log::error('Log alarm');
\Log::error('Log alarm');
\Log::error('Log alarm');

```

After the fifth error log message, email and slack notification will be sent! (Email example)

```
From: Laravel
To: admin@example.com, admin2@example.com
Subject: Log Alarm Notification

The Error was occurred 5 times in the last 1 minutes:

LOG_LEVEL: error | LOG_MESSAGE: Log alarm

```

🔧 Configuration
---------------

[](#-configuration)

Update your `.env` file with the following environment variables:

```
LA_ENABLED=true
LA_LOG_TYPE=error
LA_LOG_TIME_FRAME=1
LA_LOG_PER_TIME_FRAME=5
LA_DELAY_BETWEEN_ALARMS=5
LA_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/your/webhook/url
LA_NOTIFICATION_EMAIL=your-email@example.com
LA_NOTIFICATION_EMAIL_SUBJECT="Log Alarm Notification"

```

Here's the full configuration file content for `config/log-alarm.php`:

```
