PHPackages                             amirkateb/laralogger - 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. amirkateb/laralogger

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

amirkateb/laralogger
====================

Advanced error logger for Laravel with AI analysis and Telegram/Email notifications.

v1.0.0(9mo ago)00MITPHPPHP &gt;=8.1

Since Jul 25Pushed 9mo agoCompare

[ Source](https://github.com/amirkateb/laralogger)[ Packagist](https://packagist.org/packages/amirkateb/laralogger)[ RSS](/packages/amirkateb-laralogger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laralogger
==========

[](#laralogger)

[![GitHub Release](https://camo.githubusercontent.com/41cbca139c026ce925c4dce27f36107617f923d4acfc92b36af004ebe4cfc9c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f616d69726b617465622f6c6172616c6f67676572)](https://camo.githubusercontent.com/41cbca139c026ce925c4dce27f36107617f923d4acfc92b36af004ebe4cfc9c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f616d69726b617465622f6c6172616c6f67676572)[![GitHub License](https://camo.githubusercontent.com/a5dd95dde33c2bed60880b5b745b83247885cea9450e4fdbed820c531772e09c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616d69726b617465622f6c6172616c6f67676572)](https://camo.githubusercontent.com/a5dd95dde33c2bed60880b5b745b83247885cea9450e4fdbed820c531772e09c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616d69726b617465622f6c6172616c6f67676572)

**Laralogger** is a powerful, queue-ready Laravel error logging package that automatically captures HTTP 4xx/5xx errors and system-level issues, logs them to the database, sends customizable notifications (Telegram, Email), and even analyzes them using AI (GPT).

📄 [مطالعه داکیومنت فارسی](README.fa.md)

---

🚀 Features
----------

[](#-features)

- ✅ Logs HTTP 4xx/5xx errors with full context
- ✅ Stores logs in database (not files)
- ✅ Smart notifications (Telegram, Email, or custom)
- ✅ Optional AI error analysis via OpenAI (GPT-4/3.5)
- ✅ Queue-supported (notifications &amp; AI)
- ✅ System log scanning (e.g. NGINX error log, 502s)
- ✅ Artisan commands: simulate, cleanup, export, scan
- ✅ Fully configurable via `config/laralogger.php`
- ❌ No UI — focused on automation and performance

---

📦 Installation
--------------

[](#-installation)

```
composer require amirkateb/laralogger
php artisan vendor:publish --tag=laralogger-config
php artisan migrate
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Edit your `config/laralogger.php` to set:

- `active` → enable/disable
- `environments` → allowed environments (e.g. production, staging)
- `log_status_codes`, `notify_status_codes` → define what gets logged and notified
- `notifications` → enable queue, channels, recipient email(s)
- `ai` → OpenAI API key, model, and prompt
- `system_logs.nginx` → file path, match pattern, auto-store

You can also define a custom notification class via:

```
'notifier' => \App\Notifications\MyCustomNotifier::class
```

---

### 📣 Notification System

[](#-notification-system)

Laralogger supports sending error notifications via multiple channels such as Telegram, email, or custom handlers. Notifications are triggered after each error is logged.

#### 🔧 Configuration

[](#-configuration)

In `config/laralogger.php`, define the channels and options:

```
'notification' => [
    'enabled' => true,
    'channels' => ['telegram', 'email'], // or ['custom']
    'queue' => true,
    'queue_name' => 'notifications',

    // Optional: use your own notification class
    'custom_notifier' => \App\Notifications\CustomErrorNotifier::class,
],
```

#### 🧩 Built-in Notifiers

[](#-built-in-notifiers)

- `Laralogger\Notifications\TelegramNotifier`
- `Laralogger\Notifications\EmailNotifier`

You can add your own class implementing `Laralogger\Contracts\NotifiableInterface` and plug it into the configuration.

#### 🧪 Example

[](#-example)

```
use Laralogger\Models\ErrorLog;
use Laralogger\Services\NotificationManager;

$log = ErrorLog::latest()->first();
NotificationManager::notify($log);
```

All notifiers support queue-based delivery if enabled.
------------------------------------------------------

[](#all-notifiers-support-queue-based-delivery-if-enabled)

### 🤖 AI-Powered Error Analysis

[](#-ai-powered-error-analysis)

`Laralogger` provides optional support for AI-driven error diagnostics using OpenAI (e.g. GPT-4 or GPT-3.5). When enabled, it automatically sends a summarized error context to the selected model and stores the response (suggested cause/fix) in your database.

#### 🔧 Enable AI Analysis

[](#-enable-ai-analysis)

In `config/laralogger.php`, update the `ai` section:

```
'ai' => [
    'enabled' => true,
    'provider' => 'openai',
    'api_key' => env('LARALOGGER_AI_API_KEY'),
    'model' => 'gpt-4', // or 'gpt-3.5-turbo'
    'prompt' => "You are an expert Laravel backend developer. Given this error, explain the root cause and suggest a fix:\n\n{{error}}",
    'queue' => true, // Run analysis via queue
    'queue_name' => 'ai-analysis',
],
```

Then, set the environment variable:

```
LARALOGGER_AI_API_KEY=sk-xxxxxx

```

> ☝️ The `prompt` supports `{{error}}` as a placeholder that will be replaced with error details automatically.

#### 📦 Output

[](#-output)

- The AI-generated explanation will be saved to the `ai_analysis` field in the `error_logs` table.
- If queue is enabled, analysis will be processed asynchronously.
- You can customize the `prompt` to fit your use-case or tone.

#### 🧪 Example

[](#-example-1)

Run this to test:

```
php artisan laralog:test --code=500
```

Check your database — you should see an AI-generated explanation added to the test log entry.
---------------------------------------------------------------------------------------------

[](#check-your-database--you-should-see-an-ai-generated-explanation-added-to-the-test-log-entry)

🧪 Artisan Commands
------------------

[](#-artisan-commands)

```
php artisan laralog:test --code=500         # Simulate an error
php artisan laralog:cleanup --days=30       # Cleanup old logs
php artisan laralog:scan-nginx-log          # Scan NGINX log for critical issues
```

---

### 🗃️ Log Storage Structure

[](#️-log-storage-structure)

Laralogger stores all error logs in the database using the `error_logs` table. Each record includes detailed information about the exception, request, user, environment, and optional AI analysis.

#### 📄 Schema Overview

[](#-schema-overview)

By default, Laralogger creates the following columns in the `error_logs` table:

ColumnDescription`id`Primary key`message`Exception message`status_code`HTTP status code (e.g., 404, 500)`exception_class`Class name of the exception`file`File path where exception occurred`line`Line number`url`Request URL`method`HTTP method (GET, POST...)`user_id`ID of authenticated user (nullable)`user_type`Guarded class (e.g., App\\Models\\User)`headers`Full request headers (JSON)`payload`Request body (JSON)`ip`Request IP address`user_agent`User’s browser/device info`ai_analysis`Optional AI-generated explanation`created_at`Timestamp of the error#### 📍 Migration

[](#-migration)

To publish and run the migration:

```
php artisan vendor:publish --tag=laralogger-migrations
php artisan migrate
```

You can customize the migration to add extra columns if needed.
---------------------------------------------------------------

[](#you-can-customize-the-migration-to-add-extra-columns-if-needed)

🧾 Log Schema
------------

[](#-log-schema)

Each log entry contains:

- Status code
- Exception class &amp; message
- Request method, URL, IP, headers, payload (optional)
- User ID, name, and guard (if logged in)
- AI analysis result (if enabled)

---

### 📛 Real-time Nginx Log Scanner

[](#-real-time-nginx-log-scanner)

Laralogger can optionally monitor your Nginx error logs in real-time to catch server-level issues such as 502 Bad Gateway or 504 Gateway Timeout, even before they reach Laravel.

#### 🔧 Configuration

[](#-configuration-1)

In `config/laralogger.php`:

```
'nginx_monitoring' => [
    'enabled' => true,
    'log_path' => '/var/log/nginx/error.log',
    'patterns' => [
        '502 Bad Gateway',
        '504 Gateway Timeout',
    ],
    'interval' => 10, // in seconds
],
```

#### ⚙️ How It Works

[](#️-how-it-works)

- A background process (you can schedule it via cron or run as a systemd service) reads the last few lines of the Nginx error log.
- If any pattern matches (e.g., 502), it creates a new error log and sends notifications immediately.

#### 🧪 Example Command

[](#-example-command)

```
php artisan laralog:watch-nginx
```

You may use this inside a scheduled task or create a background service like:

```
* * * * * php /path/to/artisan laralog:watch-nginx >> /dev/null 2>&1
```

You can extend this to monitor multiple log files as well.
----------------------------------------------------------

[](#you-can-extend-this-to-monitor-multiple-log-files-as-well)

### 🔍 Webhook Logging and Route Monitoring

[](#-webhook-logging-and-route-monitoring)

Laralogger also supports **optional logging** of non-error HTTP requests such as:

- 2xx (Successful) responses
- 3xx (Redirects)
- Specific routes (e.g., payment gateways, webhooks)

This allows you to analyze traffic patterns, API behavior, or debug critical routes.

#### 🔧 Configuration

[](#-configuration-2)

```
'request_monitoring' => [
    'enabled' => true,
    'log_success' => true,
    'log_redirects' => true,
    'only_routes' => [ // Leave empty to log all
        'payment.callback',
        'webhook.telegram',
    ],
    'exclude_methods' => ['OPTIONS'],
],
```

#### 🗂️ Where Are They Logged?

[](#️-where-are-they-logged)

These logs are stored in the same `error_logs` table, with a `status_code` like `200`, `302`, etc. They are marked with a `non_exception` flag internally to differentiate.

#### 📊 Use Cases

[](#-use-cases)

- **Payment debugging**: Know what data was sent/received to/from gateways.
- **Webhook tracing**: Know exactly when and what payload came in.
- **Traffic insights**: Spot high-traffic or redirect-heavy endpoints.

---

📄 License
---------

[](#-license)

MIT © 2025 [AmirMohammad KatebSaber](mailto:amveks43@gmail.com)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance56

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

296d ago

### Community

Maintainers

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

---

Top Contributors

[![amirkateb](https://avatars.githubusercontent.com/u/56022242?v=4)](https://github.com/amirkateb "amirkateb (40 commits)")

### Embed Badge

![Health badge](/badges/amirkateb-laralogger/health.svg)

```
[![Health](https://phpackages.com/badges/amirkateb-laralogger/health.svg)](https://phpackages.com/packages/amirkateb-laralogger)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[beyondcode/laravel-server-timing

Add Server-Timing header information from within your Laravel apps.

5712.0M1](/packages/beyondcode-laravel-server-timing)[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[kitloong/laravel-app-logger

Laravel log for your application

101.2M8](/packages/kitloong-laravel-app-logger)[label84/laravel-auth-log

Log user authentication actions in Laravel.

3654.0k](/packages/label84-laravel-auth-log)

PHPackages © 2026

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