PHPackages                             sunnybyte/craft-loki-logger - 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. sunnybyte/craft-loki-logger

ActiveCraft-plugin[Logging &amp; Monitoring](/categories/logging)

sunnybyte/craft-loki-logger
===========================

Send Craft warning/error logs to Loki via its HTTP push API, using a queue job. Built for agentless, ephemeral hosts like Craft Cloud.

v1.0.1(1mo ago)189↓43.8%GPL-3.0-or-laterPHPPHP ^8.2

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/sunnybyte/craft-loki-logger)[ Packagist](https://packagist.org/packages/sunnybyte/craft-loki-logger)[ RSS](/packages/sunnybyte-craft-loki-logger/feed)WikiDiscussions main Synced 2w ago

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

Loki Logger for Craft CMS
=========================

[](#loki-logger-for-craft-cms)

Send Craft logs to a central [Loki](https://grafana.com/oss/loki/) instance via its HTTP push API, using a Craft queue job so nothing happens on the request path. The target captures the same severity levels Craft itself is configured to log (`info` in devMode, `warning` and above otherwise, or whatever your `config/app.php` sets).

Built for **Craft Cloud**, where the filesystem is ephemeral and an Alloy/Promtail agent can't be installed, but it works on any Craft 5 site. Log lines are formatted with Monolog's `JsonFormatter`, identical to the file-based JSON logs a `MonologTarget` + Alloy would emit, so they query the same way in Grafana.

How it works
------------

[](#how-it-works)

```
Craft (web / console / queue)
  -> LokiTarget        captures Craft's configured levels, formats as JSON, enqueues a job
       -> PushLogsJob   gzips + POSTs to Loki (runs in the queue worker)
            -> Loki

```

- **No request latency**: the request only enqueues a job (a DB insert). The HTTP push runs later in the queue worker, which Craft Cloud processes automatically.
- **No log storms**: a reentrancy guard plus bounded in-job retries mean a Loki outage drops the batch (best-effort) instead of recursively re-logging. Logs also stay in Cloud's native command/stdout history.
- **Low-cardinality labels**: `app="craft"`, `env`, `site`, `host`. Everything else (`level_name`, `message`, `context`, exception trace) lives in the JSON line.
- **Skips poller noise**: requests to the control panel's `queue/get-job-info`action (polled on a timer by the queue widget) are never shipped, so the CP doesn't flood Loki with near-identical lines.

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

[](#requirements)

- Craft CMS 5.0+
- PHP 8.2+

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

[](#installation)

```
composer require sunnybyte/craft-loki-logger
./craft plugin/install loki-logger
```

That's it. No `config/app.php` editing and no per-site log config: the plugin registers the log target itself once installed.

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

[](#configuration)

Configure the plugin at **Settings -&gt; Plugins -&gt; Loki Logger**. Each field accepts either a literal value or an environment variable reference (e.g. `$LOKI_API_KEY`) via Craft's native env-var autosuggest, resolved at runtime with `App::parseEnv()`.

The fields default to the `LOKI_*` env var references below, so if you set those env vars the plugin works without ever opening the settings page (useful on ephemeral hosts like Craft Cloud, where settings are read-only in production):

SettingDefault valueRequiredPurposeAPI key`$LOKI_API_KEY`YesSent as the `X-Api-Key` header. **Sending is disabled while this resolves empty**, so dev environments are no-ops by default.Push URL`$LOKI_PUSH_URL`YesLoki HTTP push endpoint. Sending is disabled while this resolves empty.Site label`$LOKI_SITE`No`site` stream label identifying this website (e.g. `www.client.com`). Falls back to the primary site host.Host label`$LOKI_HOST`No`host` stream label identifying the server (e.g. `web1`). Falls back to the machine hostname. Keep it stable and low-cardinality.The `env` label is taken from `CRAFT_ENVIRONMENT`.

Verifying
---------

[](#verifying)

```
./craft loki-logger/test
```

This pushes a line directly to Loki (immediate pass/fail on endpoint + key), then emits a sample warning and error through Craft's logger to exercise the real capture and queue path. Run `./craft queue/run` locally to deliver the queued batch; on Craft Cloud the worker delivers it automatically.

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

[](#querying-in-grafana)

Lines carry Monolog's field names, so filter on `level_name` (not `level`, which is the numeric Monolog level):

```
{app="craft", site="www.client.com"} | json | level_name="ERROR"
{app="craft"} | json | level_name="WARNING" | channel="application"

```

License
-------

[](#license)

GPL-3.0-or-later. See [LICENSE](LICENSE).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Every ~0 days

Total

2

Last Release

47d ago

### Community

Maintainers

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

---

Top Contributors

[![joshmcoffman](https://avatars.githubusercontent.com/u/970545?v=4)](https://github.com/joshmcoffman "joshmcoffman (1 commits)")

---

Tags

logginglogsCraftcraftcmscraft-pluginobservabilitygrafanalokicraft-cloud

### Embed Badge

![Health badge](/badges/sunnybyte-craft-loki-logger/health.svg)

```
[![Health](https://phpackages.com/badges/sunnybyte-craft-loki-logger/health.svg)](https://phpackages.com/packages/sunnybyte-craft-loki-logger)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

101400.6k75](/packages/verbb-formie)[verbb/hyper

A user-friendly links field for Craft.

24153.5k14](/packages/verbb-hyper)[verbb/vizy

A flexible visual editor field for Craft.

4251.5k1](/packages/verbb-vizy)[verbb/events

A full-featured plugin for event management and ticketing.

2312.1k](/packages/verbb-events)[verbb/icon-picker

A slick field to pick icons from. Supports SVGs, Sprites, Webfonts, Font Awesome and more.

16172.7k7](/packages/verbb-icon-picker)

PHPackages © 2026

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