PHP — Monolog Handler
The loginformant/monolog-handler Composer package adds a Monolog v3 handler
that batches and sends your logs to LogInformant. Works with Laravel, Symfony, or any PHP 8+ project.
1 Install
bash
composer require loginformant/monolog-handler
2 Configure the handler
php — Plain PHP
<?php
use Monolog\Logger;
use LogInformant\LogInformantHandler;
$logger = new Logger('my-app');
$logger->pushHandler(new LogInformantHandler(
apiUrl: 'https://app.loginformant.com',
apiKey: getenv('LOGINFORMANT_API_KEY'),
level: \Monolog\Level::Info,
));
3 Log in your code
php
<?php
$logger->info('Order placed', ['orderId' => $orderId, 'userId' => $userId]);
try {
// your logic
} catch (\Throwable $e) {
$logger->error('Failed to place order', [
'orderId' => $orderId,
'exception' => $e->getMessage(),
]);
}
Laravel integration
Add a custom channel in config/logging.php:
php — config/logging.php
'channels' => [
// ... existing channels ...
'loginformant' => [
'driver' => 'monolog',
'handler' => \LogInformant\LogInformantHandler::class,
'with' => [
'apiUrl' => env('LOGINFORMANT_URL', 'https://app.loginformant.com'),
'apiKey' => env('LOGINFORMANT_API_KEY'),
],
'level' => env('LOG_LEVEL', 'debug'),
],
// Or add it to your stack:
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'loginformant'],
],
],
Then in .env:
env
LOG_CHANNEL=stack LOGINFORMANT_API_KEY=your-api-key-here
In Laravel, use
Log::info(...), Log::error(...), etc. as normal.
Laravel's logging facade will automatically route to all channels in your stack.
Configuration options
| Parameter | Default | Description |
|---|---|---|
apiUrl | required | Your LogInformant instance URL |
apiKey | required | Application API key |
batchSize | 50 | Max logs per HTTP request |
level | DEBUG | Minimum Monolog level |
Log level mapping
| Monolog | LogInformant |
|---|---|
| DEBUG | Debug |
| INFO | Information |
| NOTICE / WARNING | Warning |
| ERROR / CRITICAL | Error |
| ALERT / EMERGENCY | Fatal |