PHPackages                             bureaupartners/laravel-loki-logging - 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. bureaupartners/laravel-loki-logging

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

bureaupartners/laravel-loki-logging
===================================

Zero-config Grafana Loki log driver for Laravel. Real-time, fault-tolerant, with basic auth support.

v0.1.1(3mo ago)01.0k↑2525%MITPHPPHP ^8.2

Since Feb 13Pushed 3mo agoCompare

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

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

Laravel Loki
============

[](#laravel-loki)

Zero-config Grafana Loki log driver for Laravel. Sends logs in real time to Loki via HTTP, with basic auth and built-in fault tolerance.

Features
--------

[](#features)

- **Zero-config** — just set `.env`, done
- **Real-time** — no cron job or scheduled command needed
- **Fault-tolerant** — if Loki is down, your app keeps running
- **Basic Auth** — supports authentication via reverse proxy
- **Batching** — buffers logs and sends them efficiently in batches
- **Auto-labels** — app, environment, server, level, channel are added automatically
- **No dependencies** — uses PHP's built-in cURL, no Guzzle required

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

[](#requirements)

- PHP 8.2+
- Laravel 10, 11, or 12
- PHP `ext-curl`
- A Grafana Loki server

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

[](#installation)

```
composer require bureaupartners/laravel-loki-logging
```

The service provider is loaded automatically (Laravel auto-discovery).

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

[](#configuration)

### 1. Add the Loki channel to `config/logging.php`

[](#1-add-the-loki-channel-to-configloggingphp)

```
'channels' => [

    'stack' => [
        'driver' => 'stack',
        'channels' => explode(',', env('LOG_STACK', 'daily,loki')),
        'ignore_exceptions' => false,
    ],

    'loki' => [
        'driver' => 'loki',
        'level' => env('LOG_LEVEL', 'debug'),
    ],

    // ... your other channels
],
```

### 2. Configure your `.env`

[](#2-configure-your-env)

```
LOG_CHANNEL=stack
LOG_STACK=daily,loki
LOG_LEVEL=debug

# Loki server URL
LOKI_URL=http://10.0.0.50:3100

# Unique name for this server
LOKI_SERVER=web-01

# Optional: basic auth (if you have a proxy with auth)
LOKI_AUTH_USER=
LOKI_AUTH_PASSWORD=
```

Done! All `Log::` calls now go to Loki and to your daily log file.

### 3. Optional: publish the config

[](#3-optional-publish-the-config)

```
php artisan vendor:publish --tag=loki-config
```

This creates `config/loki.php` where you can set extra labels, batch size, and timeouts.

Usage
-----

[](#usage)

Just use Laravel's standard logging:

```
use Illuminate\Support\Facades\Log;

Log::info('User logged in', ['user_id' => 123]);
Log::warning('Low stock', ['product' => 'SKU-456', 'stock' => 3]);
Log::error('Payment failed', ['order_id' => 789, 'gateway' => 'mollie']);
Log::debug('SQL query', ['query' => $sql, 'time_ms' => 45]);
```

Context is sent automatically as key=value pairs, so you can filter on it in Grafana.

Querying in Grafana
-------------------

[](#querying-in-grafana)

Open Grafana → Explore → select Loki as the datasource.

```
# All logs from a server
{server="web-01"}

# Only errors from your app
{app="my-app", level="error"}

# Search by text
{app="my-app"} |= "Payment failed"

# Errors from a specific server
{server="web-01", level="error"}

# Filter by multiple levels
{app="my-app", level=~"error|warning"}

# Search by context values
{app="my-app"} |= "order_id=789"

# Count errors per 5 minutes (for dashboards/alerts)
count_over_time({app="my-app", level="error"}[5m])

```

Advanced configuration
----------------------

[](#advanced-configuration)

### Extra labels

[](#extra-labels)

In `config/loki.php`:

```
'labels' => [
    'team' => 'backend',
    'version' => '2.1.0',
],
```

Or per channel in `config/logging.php`:

```
'loki' => [
    'driver' => 'loki',
    'level' => 'debug',
    'labels' => [
        'service' => 'api',
    ],
],
```

### Multiple Loki channels

[](#multiple-loki-channels)

```
'loki-errors' => [
    'driver' => 'loki',
    'level' => 'error',
    'url' => 'http://loki-production:3100',
],

'loki-debug' => [
    'driver' => 'loki',
    'level' => 'debug',
    'url' => 'http://loki-staging:3100',
],
```

### Channel config options

[](#channel-config-options)

OptionEnv variableDefaultDescription`url``LOKI_URL``http://localhost:3100`Loki server URL`level``LOG_LEVEL``debug`Minimum log level`auth_user``LOKI_AUTH_USER`` `Basic auth username`auth_password``LOKI_AUTH_PASSWORD`` `Basic auth password`labels`—`[]`Extra labels`batch_size``LOKI_BATCH_SIZE``10`Logs per batch`timeout``LOKI_TIMEOUT``5`HTTP timeout (sec)`connect_timeout``LOKI_CONNECT_TIMEOUT``2`Connect timeout (sec)How it works
------------

[](#how-it-works)

1. `Log::info()` calls the Loki handler
2. The handler buffers the log line (until `batch_size` is reached)
3. When the batch is full OR at the end of the PHP request → it sends everything to Loki via cURL
4. `WhatFailureGroupHandler` catches all errors — your app always keeps running
5. Labels (app, server, level, etc.) are added automatically

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance82

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67b74c6f8cf3c9512fc139dd35ffa036a923ec9d42bcde167951877ee3c7ff33?d=identicon)[markhameetman](/maintainers/markhameetman)

---

Top Contributors

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

---

Tags

loglaravelloggingmonologgrafanaloki

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/bureaupartners-laravel-loki-logging/health.svg)

```
[![Health](https://phpackages.com/badges/bureaupartners-laravel-loki-logging/health.svg)](https://phpackages.com/packages/bureaupartners-laravel-loki-logging)
```

###  Alternatives

[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

63541.6k1](/packages/ytake-laravel-fluent-logger)[codeinternetapplications/monolog-stackdriver

Stackdriver handler for Monolog.

14181.7k](/packages/codeinternetapplications-monolog-stackdriver)[thecoder/laravel-monolog-telegram

Telegram Handler for Monolog

2939.5k](/packages/thecoder-laravel-monolog-telegram)[naoray/laravel-github-monolog

Log driver to store logs as github issues

10619.4k](/packages/naoray-laravel-github-monolog)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)[yzen.dev/mono-processor

This Processor will display in the logs bread crumbs by which you can more quickly and accurately identify the cause of the error.

116.1k](/packages/yzendev-mono-processor)

PHPackages © 2026

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