Download the PHP package graftak/monolog-loki without Composer
On this page you can find all versions of the php package graftak/monolog-loki. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download graftak/monolog-loki
More information about graftak/monolog-loki
Files in graftak/monolog-loki
Package monolog-loki
Short Description Monolog handler for Grafana Loki (BC fork!)
License BSD-3-Clause
Informations about the package monolog-loki
Itspire - Monolog Loki (BC FORK!!)
! ! ! PLEASE NOTE ! ! !
This is a fork from itspire/monolog-loki for older projects still using PHP >=7.4 and Monolog 2, but with the bugfixes/improvements since version 2.0.0 applied to it. Please use https://github.com/itspire/monolog-loki or use this with care!
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_CUSTOMREQUESTCURLOPT_RETURNTRANSFERCURLOPT_POSTFIELDSCURLOPT_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
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 :
If you're testing from containerized php, 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 :