Download the PHP package itspire/monolog-loki without Composer
On this page you can find all versions of the php package itspire/monolog-loki. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itspire/monolog-loki
More information about itspire/monolog-loki
Files in itspire/monolog-loki
Package monolog-loki
Short Description Monolog handler for Grafana Loki
License BSD-3-Clause
Informations about the package monolog-loki
Itspire - Monolog Loki
This library follows the PSR-12 convention.
Usage
Recommended Usage
Since Loki log handling uses a remote server, logging is prone to be subject of timeout, network shortage and so on. To avoid your application being broken in such a case, we recommend wrapping the handler in a WhatFailureGroupHandler
Native
Non-customizable curl options
The following options are not customizable in the configuration:
CURLOPT_CUSTOMREQUEST
CURLOPT_RETURNTRANSFER
CURLOPT_POSTFIELDS
CURLOPT_HTTPHEADER
Symfony App
Configure LokiHandler Service
Note : We're currently working on a possible bundle based implementation for Symfony but at the moment, this is the way.
Configure Monolog to use Loki Handler
Laravel App
Add Loki to config/logging.php
Set env vars
These vars can be injected by Kubernetes, Docker or simply by setting them on the .env file
Laravel with WhatFailureGroupHandler
Since Loki log handling uses a remote server, logging is prone to be subject of timeout, network shortage and so on. To avoid your application being broken in such a case, we recommend wrapping the handler in a WhatFailureGroupHandler.
Create a custom Log handler and wrap the LokiHandler
with a WhatFailureGroupHandler
.
Update the config accordingly:
Testing
In order to test using the provided docker-compose file, you'll need an up-to-date docker/docker-compose installation You can start the Loki container by navigating to src/main/test/docker and running
If you're testing from a local php installation, you'll need to retrieve the Loki container ip with :
and replace the ip in the LOKI_ENTRYPOINT definition in phpunit.xml :
If you're testing from containerized php not in the default docker bridge network, you'll need to start the container with an extra host named Loki mapped to your current host ip, using the following option :
Run the test using phpunit and you can verify that posting to Loki works by running the following from your host terminal :
For each time you ran the tests, you should see a log entry looking like the following :