PHPackages                             sheenazien8/smart-log-analyzer - 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. sheenazien8/smart-log-analyzer

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

sheenazien8/smart-log-analyzer
==============================

AI-powered Laravel package for analyzing application logs, detecting patterns, and providing actionable insights

001PHP

Since Aug 12Pushed 9mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Smart Log Analyzer
==================

[](#smart-log-analyzer)

[![Smart Log Analyzer Logo](./docs/images/smart-analyze.png)](./docs/images/smart-analyze.png)

A comprehensive Laravel package that uses AI/ML techniques to analyze application logs, identify patterns, detect anomalies, and provide actionable insights through a web dashboard and automated alerts.

Features
--------

[](#features)

- **Intelligent Log Parsing**: Automatically parse Laravel's default log format and structured logs
- **Pattern Recognition**: Group similar errors using advanced text similarity algorithms
- **Anomaly Detection**: Identify unusual patterns and sudden spikes in error rates
- **Real-time Monitoring**: Watch for new log entries as they're written
- **Web Dashboard**: Beautiful, responsive interface with charts and metrics
- **Automated Alerts**: Email notifications for critical issues with intelligent throttling
- **API Access**: RESTful API for integration with external tools
- **Background Processing**: Efficient queue-based log processing

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

[](#requirements)

- PHP 8.1+
- Laravel 9.x, 10.x, or 11.x
- **Database**: MySQL 5.7+, PostgreSQL 12+, or SQLite 3.25+
- Queue worker (Redis, database, or other Laravel-supported drivers)

### Database Compatibility

[](#database-compatibility)

The package automatically detects your database driver and uses appropriate SQL syntax:

- **MySQL**: Uses `DATE_FORMAT()` and MySQL-specific functions
- **PostgreSQL**: Uses `TO_CHAR()` and PostgreSQL-specific functions
- **SQLite**: Uses `strftime()` and SQLite-specific functions

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

[](#installation)

1. Install the package via Composer:

```
composer require sheenazien8/smart-log-analyzer
```

2. Publish and run the migrations:

```
php artisan vendor:publish --provider="SmartLogAnalyzer\SmartLogAnalyzerServiceProvider"
php artisan migrate
```

3. Install the package:

```
php artisan smart-log:install
```

4. Configure your log paths in `config/smart-log-analyzer.php`
5. Start queue workers:

```
php artisan queue:work
```

6. Schedule the analysis command in your `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('smart-log:analyze --incremental --detect-anomalies --process-alerts')
             ->everyFiveMinutes();
}
```

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

[](#configuration)

The main configuration file is published to `config/smart-log-analyzer.php`. Key settings include:

### Log Paths

[](#log-paths)

```
'log_paths' => [
    storage_path('logs/laravel.log'),
    storage_path('logs'),
],
```

### Pattern Recognition

[](#pattern-recognition)

```
'pattern_recognition' => [
    'similarity_threshold' => 0.8,
    'min_occurrences' => 3,
    'time_window' => 3600, // seconds
],
```

### Anomaly Detection

[](#anomaly-detection)

```
'anomaly_detection' => [
    'enabled' => true,
    'spike_threshold' => 5.0,
    'minimum_baseline_hours' => 24,
],
```

### Email Alerts

[](#email-alerts)

```
'alerts' => [
    'enabled' => true,
    'email' => [
        'recipients' => ['dev@example.com'],
        'throttle_minutes' => 60,
    ],
],
```

Usage
-----

[](#usage)

### Web Dashboard

[](#web-dashboard)

Access the dashboard at `/smart-log-analyzer` (configurable). The dashboard provides:

- **Overview**: Summary statistics and trends
- **Error Patterns**: Grouped similar errors with occurrence counts
- **Anomalies**: Detected unusual patterns and spikes
- **Raw Logs**: Searchable and filterable log entries

### Artisan Commands

[](#artisan-commands)

#### Install the package

[](#install-the-package)

```
php artisan smart-log:install
```

#### Analyze logs manually

[](#analyze-logs-manually)

```
# Analyze all configured log files
php artisan smart-log:analyze

# Analyze specific file
php artisan smart-log:analyze --file=/path/to/log/file

# Incremental analysis (only new entries)
php artisan smart-log:analyze --incremental

# Include anomaly detection and alert processing
php artisan smart-log:analyze --detect-anomalies --process-alerts
```

#### Test database compatibility

[](#test-database-compatibility)

```
# Test database-specific functions
php artisan smart-log:test-database
```

### API Endpoints

[](#api-endpoints)

The package provides RESTful API endpoints:

```
GET /api/smart-log-analyzer/stats          # Dashboard statistics
GET /api/smart-log-analyzer/patterns       # Error patterns
GET /api/smart-log-analyzer/anomalies      # Detected anomalies
GET /api/smart-log-analyzer/logs           # Raw log entries
```

How It Works
------------

[](#how-it-works)

### 1. Log Parsing

[](#1-log-parsing)

The package parses Laravel log files using regex patterns to extract:

- Timestamp and log level
- Channel and message content
- Exception classes and stack traces
- File paths and line numbers

### 2. Pattern Recognition

[](#2-pattern-recognition)

Similar errors are grouped using multiple similarity algorithms:

- **Levenshtein Distance**: Character-level similarity
- **Cosine Similarity**: Word-based similarity using TF-IDF
- **Jaccard Similarity**: Set-based similarity

Messages are normalized by replacing dynamic values (numbers, UUIDs, IPs) with placeholders.

### 3. Anomaly Detection

[](#3-anomaly-detection)

The system detects several types of anomalies:

- **Error Rate Spikes**: Sudden increases in error frequency
- **Volume Anomalies**: Unusual changes in total log volume
- **Pattern Anomalies**: Existing patterns showing unusual behavior
- **New Critical Patterns**: First occurrence of critical errors

### 4. Alert System

[](#4-alert-system)

Configurable alert rules trigger notifications based on:

- **Threshold Rules**: When metrics exceed defined limits
- **Anomaly Rules**: When anomalies are detected
- **Pattern Rules**: When specific error patterns occur

Advanced Features
-----------------

[](#advanced-features)

### Custom Pattern Recognition

[](#custom-pattern-recognition)

You can extend pattern recognition by implementing custom similarity algorithms:

```
use SmartLogAnalyzer\Services\PatternAnalyzer;

class CustomPatternAnalyzer extends PatternAnalyzer
{
    protected function calculateCustomSimilarity(string $message1, string $message2): float
    {
        // Your custom similarity logic
        return $similarity;
    }
}
```

### Custom Alert Channels

[](#custom-alert-channels)

Add support for additional notification channels:

```
use SmartLogAnalyzer\Jobs\SendAlertJob;

class CustomAlertJob extends SendAlertJob
{
    protected function sendCustomAlert(): void
    {
        // Your custom alert logic
    }
}
```

### Real-time Log Monitoring

[](#real-time-log-monitoring)

Enable real-time monitoring for immediate processing:

```
use SmartLogAnalyzer\Services\LogParser;

$logParser = app(LogParser::class);
$logParser->watchLogFile('/path/to/log', function ($entry) {
    // Process new log entry immediately
});
```

Performance Considerations
--------------------------

[](#performance-considerations)

### Memory Usage

[](#memory-usage)

- Configure `processing.memory_limit` for large log files
- Use `processing.batch_size` to control memory consumption
- Enable `storage.compress_old_data` for long-term storage

### Queue Configuration

[](#queue-configuration)

- Use Redis or database queues for better performance
- Configure multiple queue workers for parallel processing
- Set appropriate `processing.timeout` values

### Caching

[](#caching)

- Enable caching for improved dashboard performance
- Configure cache TTL based on your needs
- Use Redis for better cache performance

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

[](#troubleshooting)

### Common Issues

[](#common-issues)

**MySQL index name too long error**If you encounter "Identifier name is too long" errors during migration:

```
php artisan smart-log:fix-indexes
```

**PostgreSQL function errors**If you see "function does not exist" errors, the package should automatically handle this. Test compatibility:

```
php artisan smart-log:test-database
```

**Queue jobs failing**

- Check queue worker is running: `php artisan queue:work`
- Verify log file permissions are readable
- Check memory limits in configuration

**Dashboard not loading**

- Ensure migrations have been run
- Check web server configuration
- Verify middleware configuration

**No patterns detected**

- Check log paths configuration
- Verify log files contain parseable entries
- Lower similarity threshold if needed

**Alerts not sending**

- Verify email configuration
- Check alert rule conditions
- Ensure queue workers are processing alert jobs

**Migration issues**If migrations fail, try:

```
php artisan migrate:fresh
php artisan smart-log:install --skip-migration
```

### Debug Mode

[](#debug-mode)

Enable verbose logging by setting `LOG_LEVEL=debug` in your `.env` file.

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

[](#contributing)

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The Smart Log Analyzer package is open-sourced software licensed under the [MIT license](LICENSE.md).

Support
-------

[](#support)

- Issues: [GitHub Issues](https://github.com/sheenazien8/smart-log-analyzer/issues)
- Discussions: [GitHub Discussions](https://github.com/sheenazien8/smart-log-analyzer/discussions)

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance42

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ed1a4b2439b93f675e34da1edd32c374924e53bb2eb0843bdd727f46a9412bb?d=identicon)[sheenazien8](/maintainers/sheenazien8)

---

Top Contributors

[![sheenazien8](https://avatars.githubusercontent.com/u/37477023?v=4)](https://github.com/sheenazien8 "sheenazien8 (7 commits)")

### Embed Badge

![Health badge](/badges/sheenazien8-smart-log-analyzer/health.svg)

```
[![Health](https://phpackages.com/badges/sheenazien8-smart-log-analyzer/health.svg)](https://phpackages.com/packages/sheenazien8-smart-log-analyzer)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/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.2M137](/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)
