Introduction
The Lescopr PHP SDK integrates with Symfony through LescoprBundle, a dedicated Symfony bundle that wires the Monolog handler and kernel exception subscriber into the Symfony DI container.
Once registered, all Monolog log entries and unhandled kernel exceptions are automatically captured and forwarded to your Lescopr dashboard.
The package is available on Packagist and is compatible with Symfony 4.4+ and PHP 7.4+.
Requirements
Erreur de chargement
Installation
Install the package via Composer:
Then register the bundle in config/bundles.php:
Or if you use Symfony Flex, the bundle is registered automatically.
composer require lescopr/lescopr-phpreturn [
// ...
Lescopr\Integrations\Symfony\LescoprBundle::class => ['all' => true],
];Configuration
Wire the Monolog handler in config/packages/monolog.yaml:
Register services in config/services.yaml:
Add your keys to .env:
Available options:
sdk_key— Your Lescopr SDK key (required)api_key— Your Lescopr API key (required)environment— The current environment (production,staging,development)
monolog:
handlers:
lescopr:
type: service
id: Lescopr\Integrations\Symfony\LescoprMonologHandler
channels: ['!event', '!doctrine']services:
Lescopr\Core\Lescopr:
factory: ['Lescopr\Core\Lescopr', 'fromConfig']
public: true
Lescopr\Integrations\Symfony\LescoprMonologHandler:
arguments: ['@Lescopr\Core\Lescopr']
Lescopr\Integrations\Symfony\EventSubscriber\KernelExceptionSubscriber:
arguments: ['@Lescopr\Core\Lescopr']
tags:
- { name: kernel.event_subscriber }LESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
LESCOPR_ENVIRONMENT=productionUsage
Once configured, all Monolog log entries are forwarded automatically to Lescopr:
Kernel exceptions are captured automatically via KernelExceptionSubscriber, registered as a kernel.event_subscriber.
You can also report exceptions manually anywhere in your application:
use Psr\Log\LoggerInterface;
class OrderController extends AbstractController
{
public function __construct(private LoggerInterface $logger) {}
public function checkout(): Response
{
$this->logger->info('Checkout started', ['user' => $this->getUser()?->getId()]);
// ...
}
}use Lescopr\Core\Lescopr;
class PaymentService
{
public function __construct(private Lescopr $lescopr) {}
public function process(Order $order): void
{
try {
$this->gateway->charge($order);
} catch (\Throwable $e) {
$this->lescopr->report($e);
throw $e;
}
}
}Advanced
CLI initialisation
Initialise the SDK from the command line to auto-detect your framework, register the project, and start the daemon:
Diagnose
Run a full diagnostic including PHP environment, config validity, daemon state, and HTTPS connectivity:
Environment variables
LESCOPR_SDK_KEY— SDK key (overrides.lescopr.json)LESCOPR_API_KEY— API keyLESCOPR_ENVIRONMENT—developmentorproductionLESCOPR_DEBUG=true— Enables verbose output to.lescopr.log
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY./vendor/bin/lescopr diagnose --details --check-server