定制 darkton/laravel-loki 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

darkton/laravel-loki

最新稳定版本:0.0.2-beta

Composer 安装命令:

composer require darkton/laravel-loki

包简介

A Laravel package for shipping logs to Grafana Loki via OTLP with Redis buffering.

README 文档

README

⚠️ Beta release
The API is considered stable for testing and production use, but may change before the first stable release (v1.0.0).

A Laravel logging package that ships logs to Grafana Loki via OTLP, built on top of Monolog.

It uses Redis buffering and queued jobs to ensure safe, asynchronous delivery without impacting application performance or creating logging feedback loops.

Installation

You can install the package directly via Packagist using Composer:

composer require darkton/laravel-loki

After installation, you can optionally publish the configuration file (useful for customizing Grafana access, batch limits, and queues to be used):

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

Basic Configuration (.env)

In your .env file, you will need to set up the following Grafana Loki credentials to be able to send logs:

LOKI_OTLP_ENDPOINT="https://logs-prod-...grafana.net/otlp/v1/logs"
LOKI_USERNAME="your_stack_id"
LOKI_API_KEY="your_access_token"

How to access / Basic Usage

To enable sending logs to loki, you must register this channel in Laravel's logging structure. In your config/logging.php file, add it to the channels array:

'channels' => [
    // ...

    'loki' => [
        'driver' => 'monolog',
        'handler' => \Darkton\Loki\Logging\LokiRedisHandler::class,
    ],
],

Now you can log normally and direct your default stack to "loki" or access the channel directly:

use Illuminate\Support\Facades\Log;

Log::channel('loki')->info('This log will be saved in Redis and later dispatched to Loki!');

The Dispatcher (Sync Command)

Monolog's LokiRedisHandler does not send HTTP requests immediately. Instead, it saves them in a secure Redis list (buffer).

To actually ship these logs to Grafana Loki, you need to call the sync command. It will read the buffer, split it into organized batches, and dispatch a Laravel Job to perform the OTLP async request:

You can call it manually:

php artisan loki:sync

Ideally, you should schedule it in your console infrastructure (routes/console.php or app/Console/Kernel.php depending on your Laravel version):

use Illuminate\Support\Facades\Schedule;

Schedule::command('loki:sync')->everyMinute();

Tip: Make sure your queue:work supervisors or Horizon are running on your server, as the heavy pushing is offloaded to your application's queues!

License

This package is distributed and licensed under the terms of the MIT license.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固