1. Go to this page and download the library: Download itspire/monolog-loki library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itspire / monolog-loki example snippets
use Itspire\MonologLoki\Handler\LokiHandler;
use Monolog\Handler\WhatFailureGroupHandler;
$handler = new WhatFailureGroupHandler(
[
new LokiHandler(
[
'entrypoint' => 'https://loki:3100',
'context' => [
// Set here your globally applicable context variables
],
'labels' => [
// Set here your globally applicable labels
],
'client_name' => 'your_host_name', // Here set a unique identifier for the client host
// Optional: Sets tenant id (HTTP header X-Scope-OrgID), if null or missing -> no header
'tenant_id' => 'some-tenant',
// Optional : if you're using basic auth to authentify
'auth' => [
'basic' => ['user', 'password'],
],
// Optional : Override the default curl options with custom values
'curl_options' => [
CURLOPT_CONNECTTIMEOUT_MS => 500,
CURLOPT_TIMEOUT_MS => 600
]
]
)
]
);
namespace App\Logging;
use Itspire\MonologLoki\Formatter\LokiFormatter;
use Itspire\MonologLoki\Handler\LokiHandler;
use Monolog\Handler\WhatFailureGroupHandler;
use Monolog\Logger;
class LokiNoFailureHandler
{
public function __invoke(array $config)
{
return new Logger('loki-no-failure', [
new WhatFailureGroupHandler([
(new LokiHandler($config['handler_with']['apiConfig'], $config['level']))
->setFormatter(new LokiFormatter(...array_values($config['formatter_with'])))
])
]);
}
}