Laravel — Lescopr SDK

Integrate the Lescopr SDK into your Laravel application for automatic exception capture, Monolog integration, and real-time monitoring.

Introduction

The Lescopr PHP SDK integrates seamlessly with Laravel via a Service Provider that is registered automatically through Composer's package auto-discovery.

Once installed, all Log::error(), Log::warning() and unhandled exceptions are captured and forwarded in real-time to your Lescopr dashboard.

The package is available on Packagist and is compatible with Laravel 8+ and PHP 7.4+.

Requirements

Erreur de chargement

Installation

Install the package via Composer:

The Service Provider is registered automatically via Laravel's package auto-discovery — no manual registration needed.

Optionally, publish the config file to customise defaults:

Terminal
bash
composer require lescopr/lescopr-php
Terminal
bash
php artisan vendor:publish --tag=lescopr-config

Configuration

Add your keys to your .env file:

Then add the Lescopr channel to your logging stack in config/logging.php:

Available options:

  • sdk_key — Your Lescopr SDK key (required)
  • api_key — Your Lescopr API key (required)
  • environment — The current environment (production, staging, development)
  • LESCOPR_DEBUG=true — Enables verbose output to .lescopr.log
.env
dotenv
LESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
LESCOPR_ENVIRONMENT=production
config/logging.php
php
'channels' => [
    'stack' => [
        'driver'   => 'stack',
        'channels' => ['single', 'lescopr'],
    ],
    'lescopr' => [
        'driver'      => 'monolog',
        'handler'     => \Lescopr\Integrations\Laravel\Logging\LescoprMonologHandler::class,
        'handler_with' => [
            'sdk' => app(\Lescopr\Core\Lescopr::class),
        ],
    ],
],

Usage

Once configured, all log calls are forwarded automatically to Lescopr via the Monolog handler:

Unhandled exceptions are also captured automatically via the exception handler decorator bundled with the LescoprServiceProvider.

You can also log manually anywhere in your application:

app/Http/Controllers/OrderController.php
php
use Illuminate\Support\Facades\Log;

Log::info('Order placed', ['order_id' => $order->id]);
Log::error('Payment failed', ['reason' => $e->getMessage()]);
app/Services/PaymentService.php
php
try {
    $this->processPayment($order);
} catch (\Throwable $e) {
    app(\Lescopr\Core\Lescopr::class)->report($e);
    throw $e;
}

Advanced

Initialising via CLI

You can initialise the SDK from the command line. This detects your framework, registers the project, writes .lescopr.json, and starts the background daemon:

Daemon management

The background daemon flushes your log queue every 5 seconds via HTTPS — completely non-blocking:

Environment variables

  • LESCOPR_SDK_KEY — SDK key (overrides .lescopr.json)
  • LESCOPR_API_KEY — API key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DAEMON_MODE=true — Prevents the SDK from forking inside its own daemon
  • LESCOPR_DEBUG=true — Enables verbose output to .lescopr.log
Terminal
bash
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY
Terminal
bash
./vendor/bin/lescopr start
./vendor/bin/lescopr status
./vendor/bin/lescopr stop