PHPackages                             hassanjrao/laravel-ai-log-search - 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. [Search &amp; Filtering](/categories/search)
4. /
5. hassanjrao/laravel-ai-log-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

hassanjrao/laravel-ai-log-search
================================

AI-assisted, natural-language log file search for Laravel. Streams huge log files without loading them into memory and turns plain-language questions into structured filters via Gemini or any OpenAI-compatible API.

v1.0.0(1mo ago)01MITPHPPHP ^7.2.5|^8.0

Since Jul 14Pushed 1mo agoCompare

[ Source](https://github.com/hassanjrao/ai-assisted-log-search)[ Packagist](https://packagist.org/packages/hassanjrao/laravel-ai-log-search)[ RSS](/packages/hassanjrao-laravel-ai-log-search/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Laravel AI Log Search
=====================

[](#laravel-ai-log-search)

AI-assisted, natural-language search over your Laravel log files — built for **very large logs** (hundreds of MB) that normal log viewers choke on.

Ask in plain language:

> *"errors that happened today"* · *"entries mentioning PaymentJob after 2 pm"* · *"critical entries related to user 4521"*

The AI turns your request into a **structured filter** (levels, keywords, date range) — it never reads your log file. A deterministic streaming scanner then applies that filter to the file:

- **Flat memory** — the file is read backwards in 64 KB chunks; a 2 GB log uses the same memory as a 2 KB one.
- **Newest first** — results stream from the end of the file.
- **Bounded requests** — each request stops at a match limit *and* a byte-scan budget (default 50 MB), returning a byte offset so "Load older" resumes exactly where it left off.
- **Multi-line aware** — stack traces and context lines are grouped with their entry.
- **Redaction** — emails, bearer tokens, obvious secrets, and long digit runs are masked before entries reach the browser.
- **Works without AI** — with `driver=none` (the default) the prompt is used as a plain keyword search. No API key needed to try it.

The UI is a single self-contained page (vanilla JS, no build step, no frontend framework required).

Demo
----

[](#demo)

🎥 [Watch a quick demo on Loom](https://www.loom.com/share/05dad156422b40c8bedf466b84b63ec7)

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

[](#requirements)

- PHP 7.2.5+ or 8.x
- Laravel 7 – 12

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

[](#installation)

```
composer require hassanjrao/laravel-ai-log-search
```

The service provider is auto-discovered. Visit `/ai-log-search` (in the `local` environment it works immediately).

### Authorization (required outside local)

[](#authorization-required-outside-local)

Like Telescope, the page is open in the `local` environment only. Anywhere else you must define a `viewAiLogSearch` gate (e.g. in `AuthServiceProvider::boot()`):

```
use Illuminate\Support\Facades\Gate;

Gate::define('viewAiLogSearch', function ($user) {
    return in_array($user->email, ['admin@example.com']);
    // or: return $user->hasPermissionTo('view-log-search');
});
```

### Enable AI interpretation (optional)

[](#enable-ai-interpretation-optional)

Pick a driver in `.env`:

```
# Google Gemini
AI_LOG_SEARCH_DRIVER=gemini
AI_LOG_SEARCH_GEMINI_KEY=your-key
AI_LOG_SEARCH_GEMINI_MODEL=gemini-2.5-flash

# ...or any OpenAI-compatible API (OpenAI, Azure, Groq, Ollama, LM Studio, ...)
AI_LOG_SEARCH_DRIVER=openai
AI_LOG_SEARCH_OPENAI_KEY=your-key
AI_LOG_SEARCH_OPENAI_MODEL=gpt-4o-mini
AI_LOG_SEARCH_OPENAI_BASE_URL=https://api.openai.com/v1
```

If the AI call fails or returns garbage, the package silently falls back to searching the raw prompt as a keyword — the page keeps working.

#### Custom AI provider

[](#custom-ai-provider)

Bind your own implementation of `Hassanjrao\AiLogSearch\Contracts\AiClient` in a service provider:

```
$this->app->bind(\Hassanjrao\AiLogSearch\Contracts\AiClient::class, MyAnthropicClient::class);
```

`completeJson(string $instruction): ?array` receives the interpretation prompt and must return the decoded JSON filter (or `null`).

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

[](#configuration)

```
php artisan vendor:publish --tag=ai-log-search-config
```

Key options in `config/ai-log-search.php`:

OptionDefaultDescription`route_prefix``ai-log-search`URL prefix for the page and its API.`middleware``['web']`Middleware stack (the authorize middleware is always appended).`log_dir``storage/logs`Directory scanned for `*.log` files.`driver``none``gemini`, `openai`, or `none` (keyword-only).`limits.entries_per_page``200`Max matching entries per request.`limits.byte_budget``50 MB`Max bytes scanned per request.`redact``true`Mask likely PII/secrets in returned entries.To customize the page itself:

```
php artisan vendor:publish --tag=ai-log-search-views
```

HTTP API
--------

[](#http-api)

All endpoints live under the configured prefix and honor the same authorization.

MethodEndpointBodyReturns`GET``/files`—`{files: [{name, size, size_human, modified}]}``POST``/query``{file, prompt}`interpreted `filter`, `explanation`, plus the first result page`POST``/results``{file, filter, offset}``{entries, next_offset, eof, file_size, scanned_bytes}``offset` is the byte position returned as `next_offset` by the previous page (`0` = start from the end of the file). `filter` shape:

```
{
  "levels": ["ERROR", "CRITICAL"],
  "keywords": ["PaymentJob"],
  "date_from": "2026-07-14 00:00:00",
  "date_to": null
}
```

Security notes
--------------

[](#security-notes)

- File names from the client are reduced to their base name and resolved with `realpath()` inside the configured log directory — path traversal is not possible, and only `*.log` files are served.
- The AI provider receives **only the user's prompt and the file's date** — never log contents.
- Client-supplied filters are re-validated server-side (levels are whitelisted).

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/603e7821240047589d1934e1852d60ae5b1e875d9ef91b836e674e713a543dd8?d=identicon)[hassanjrao](/maintainers/hassanjrao)

---

Top Contributors

[![hassanjrao](https://avatars.githubusercontent.com/u/52125125?v=4)](https://github.com/hassanjrao "hassanjrao (2 commits)")

---

Tags

searchlaravelailogsopenailog viewerGemini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hassanjrao-laravel-ai-log-search/health.svg)

```
[![Health](https://phpackages.com/badges/hassanjrao-laravel-ai-log-search/health.svg)](https://phpackages.com/packages/hassanjrao-laravel-ai-log-search)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k118.2M1.0k](/packages/laravel-socialite)[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.6M77](/packages/spatie-laravel-responsecache)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1346.4k29](/packages/fleetbase-core-api)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1349.6k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

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