lognitor/lognitor (PHP)

PHP SDK for Lognitor with Laravel, Symfony, and WordPress integrations. PSR-3 compatible.

Installation

Terminal
composer require lognitor/lognitor

Quick 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

OptionTypeDefaultDescription
api_keystringRequired. Your project API key.
api_urlstringhttps://api.lognitor.com/api/v1API endpoint.
servicestringnullService/app name.
environmentstringnullEnvironment label.
versionstringnullApp version.
batch_sizeint25Logs per batch.
flush_intervalfloat5.0Auto-flush interval in seconds.
max_retriesint3Retry count for failed requests.
max_queue_sizeint1000Maximum logs held in memory.
min_levelstring | nullnullMinimum log level.
enabledbooltrueMaster switch.
auto_truncateboolfalseTruncate instead of dropping oversized logs.
max_breadcrumbsint100Max breadcrumbs.
debugboolfalsePrint SDK debug messages.
redact_patternsstring[][]Built-in: email, creditCard, ssn, bearer.
before_sendcallablenullfn(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.
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-config

2. Set Environment Variables

env
LOGNITOR_API_KEY=your-api-key
LOGNITOR_SERVICE=my-laravel-app
LOGNITOR_ENVIRONMENT=production

3. 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:test

Symfony 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 sending

Reconfigure

PHP
Lognitor::reconfigure([
'min_level' => 'warn',
'enabled' => false,
'debug' => true,
]);