lognitor/lognitor (PHP)
PHP SDK for Lognitor with Laravel, Symfony, and WordPress integrations. PSR-3 compatible.
Installation
Terminal
composer require lognitor/lognitorQuick Start
PHP
use Lognitor\Lognitor;
Lognitor::init([
'api_key' => 'your-api-key',
'service' => 'my-php-app',
'environment' => 'production',
'version' => '1.2.0',
]);
Lognitor::info('Server started');
Lognitor::error('Database connection failed', [
'error' => ['type' => 'ConnectionError', 'message' => 'ECONNREFUSED'],
'metadata' => ['host' => 'db.internal', 'port' => 5432],
]);Configuration
PHP
$client = Lognitor::init([
'api_key' => 'your-api-key',
'service' => 'payment-service',
'environment' => 'production',
'version' => '2.1.0',
'batch_size' => 25,
'flush_interval' => 5.0,
'max_queue_size' => 1000,
'max_retries' => 3,
'min_level' => 'info',
'enabled' => true,
'redact_patterns' => ['email', 'creditCard', 'ssn', 'bearer'],
'scrub_url_params' => ['token', 'password', 'secret', 'authorization'],
'auto_truncate' => true,
'max_breadcrumbs' => 100,
'debug' => false,
'before_send' => function (array $log): ?array {
if (str_contains($log['message'], 'healthcheck')) return null;
return $log;
},
]);Configuration Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
api_key | string | — | Required. Your project API key. |
api_url | string | https://api.lognitor.com/api/v1 | API endpoint. |
service | string | null | Service/app name. |
environment | string | null | Environment label. |
version | string | null | App version. |
batch_size | int | 25 | Logs per batch. |
flush_interval | float | 5.0 | Auto-flush interval in seconds. |
max_retries | int | 3 | Retry count for failed requests. |
max_queue_size | int | 1000 | Maximum logs held in memory. |
min_level | string | null | null | Minimum log level. |
enabled | bool | true | Master switch. |
auto_truncate | bool | false | Truncate instead of dropping oversized logs. |
max_breadcrumbs | int | 100 | Max breadcrumbs. |
debug | bool | false | Print SDK debug messages. |
redact_patterns | string[] | [] | Built-in: email, creditCard, ssn, bearer. |
before_send | callable | null | fn(array): ?array. Return null to drop. |
Log Levels
PHP
Lognitor::debug('Cache miss', ['metadata' => ['key' => 'user:123']]);
Lognitor::info('Order created', ['metadata' => ['order_id' => 'ord_456']]);
Lognitor::warn('Rate limit approaching', ['metadata' => ['usage' => 850]]);
Lognitor::error('Payment failed', ['error' => new \RuntimeException('Card declined')]);
Lognitor::fatal('Database corrupted');
Lognitor::log('info', 'Custom level call');Error Capturing
PHP
try {
processPayment($order);
} catch (\Throwable $e) {
Lognitor::captureException($e, [
'metadata' => ['order_id' => $order->id],
'tags' => ['payment', 'critical'],
]);
}
// PHP errors (E_WARNING, E_NOTICE) are captured automatically via set_error_handler.
// Fatal errors are captured via register_shutdown_function.Breadcrumbs
PHP
Lognitor::addBreadcrumb('http', 'api', 'GET /api/users 200', 'info', [
'duration_ms' => 45,
]);
Lognitor::error('Order processing failed', [
'error' => new \RuntimeException('Insufficient stock'),
]);Timers
PHP
$timer = Lognitor::startTimer();
$result = heavyComputation();
$timer->end('Computation finished', [
'metadata' => ['input_size' => 1000],
'perf' => ['db_queries' => 5],
]);Child Loggers
PHP
$client = Lognitor::init(['api_key' => 'your-key', 'service' => 'main-app']);
$paymentLogger = $client->child([
'service' => 'payment-module',
'metadata' => ['module' => 'payment'],
'tags' => ['payments'],
]);
$paymentLogger->info('Processing payment');Heartbeat Monitoring
PHP
$hb = Lognitor::heartbeat('your-monitor-token');
$hb->ping();
$result = $hb->wrap(function () {
return syncInventory();
});User Feedback
PHP
$logId = Lognitor::error('Checkout failed', [
'error' => new \RuntimeException('Payment timeout'),
]);
Lognitor::submitFeedback([
'event_id' => $logId,
'comments' => 'Page froze when I clicked pay',
'name' => 'Alice',
'email' => 'alice@acme.com',
]);Release Tracking
PHP
$release = Lognitor::registerRelease([
'version' => '2.1.0',
'commit_hash' => 'a1b2c3d4e5f6',
'branch' => 'main',
'deployed_by' => 'github-actions',
]);Laravel Integration
1. Publish Config
Terminal
php artisan vendor:publish --tag=lognitor-config2. Set Environment Variables
env
LOGNITOR_API_KEY=your-api-key
LOGNITOR_SERVICE=my-laravel-app
LOGNITOR_ENVIRONMENT=production3. Add Middleware
PHP
// app/Http/Kernel.php
protected $middleware = [
\Lognitor\Integrations\Laravel\LognitorMiddleware::class,
];4. Config File
PHP
// config/lognitor.php
return [
'api_key' => env('LOGNITOR_API_KEY'),
'service' => env('LOGNITOR_SERVICE', 'my-laravel-app'),
'environment' => env('LOGNITOR_ENVIRONMENT', 'production'),
'ignore_routes' => ['/health', '/ready'],
'capture_user' => true,
];5. Test the Connection
Terminal
php artisan lognitor:testSymfony Integration
PHP
// config/packages/lognitor.php
use Lognitor\Integrations\Symfony\LognitorBundle;
return static function ($container) {
$container->loadFromExtension('lognitor', [
'api_key' => '%env(LOGNITOR_API_KEY)%',
'service' => 'my-symfony-app',
'environment' => '%kernel.environment%',
]);
};WordPress Integration
PHP
// wp-config.php
define('LOGNITOR_API_KEY', 'your-api-key');
define('LOGNITOR_SERVICE', 'my-wordpress-site');
define('LOGNITOR_ENVIRONMENT', 'production');Activate the Lognitor plugin from the WordPress admin panel.
PSR-3 Logger
PHP
use Lognitor\PsrLogger;
$logger = new PsrLogger(Lognitor::getInstance());
$logger->info('Order created', ['order_id' => 'ord_123']);
$logger->error('Payment failed', [
'exception' => new \RuntimeException('Card declined'),
]);Flush and Shutdown
PHP
Lognitor::flush(); // Send all buffered logs
Lognitor::shutdown(); // Flush and clean up
// The SDK registers a shutdown function that auto-flushes on script end.Pause and Resume
PHP
Lognitor::pause(); // Stop sending (still buffers)
Lognitor::resume(); // Resume sendingReconfigure
PHP
Lognitor::reconfigure([
'min_level' => 'warn',
'enabled' => false,
'debug' => true,
]);