tomas-kulhanek / monolog-loki
Loki handler for Monolog
v1.0.0
2025-07-17 12:35 UTC
Requires
- php: >=8.2
- ext-curl: *
- monolog/monolog: ^3
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5
- rector/rector: ^2.1
- shipmonk/phpstan-rules: ^4.1
- slevomat/coding-standard: ^8.19
- squizlabs/php_codesniffer: ^3.13
README
Loki handler for Monolog, providing a formatter that serializes records into the JSON format expected by Grafana Loki.
Table of Contents
Installation
Require the package via Composer:
composer require tomas-kulhanek/monolog-loki
Usage
Below is a minimal example showing how to send logs to a Loki server:
use Monolog\Level;
use Monolog\Logger;
use TomasKulhanek\Monolog\Loki\LokiHandler;
$handler = new LokiHandler(
'http://your-loki-host:3100',
'username',
'password',
['app'=>'My application', 'env'=>'production'],
Level::Debug
);
$logger = new Logger('loki');
$logger->pushHandler($handler);
$logger->info('User signed in', ['user_id' => 123]);
Contributing
Contributions are very welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Make your changes, ensuring all tests pass and coding standards are met.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
