dennisvanbeersel/symfony-logger-client
Since this is a Symfony bundle, Laravel integration requires Symfony Bridge or Laravel Symfony Integration (e.g., spatie/laravel-symfony-support). Start with:
composer require dennisvanbeersel/symfony-logger-client spatie/laravel-symfony-support
Publish Config Copy the bundle’s config to Laravel’s config:
php artisan vendor:publish --provider="DennisVanBeersel\ApplicationLogger\ApplicationLoggerBundle" --tag="config"
Update .env with:
APPLICATION_LOGGER_DSN=https://applogger.eu/your-project-uuid
APPLICATION_LOGGER_API_KEY=your-64-char-key
Register Bundle
In config/app.php, add the bundle to providers:
DennisVanBeersel\ApplicationLogger\ApplicationLoggerBundle::class,
First Log
Use the ApplicationLogger service in a controller or service:
use DennisVanBeersel\ApplicationLogger\ApplicationLogger;
public function __construct(private ApplicationLogger $logger) {}
public function handleError() {
$this->logger->error('Test error', [
'context' => ['user_id' => auth()->id(), 'trace' => true],
]);
}
Error Tracking
try-catch blocks with $logger->error():
try {
$user->delete();
} catch (\Exception $e) {
$this->logger->error('Failed to delete user', [
'exception' => $e,
'user_id' => $user->id,
]);
}
$this->logger->error('API request failed', [
'url' => $request->url(),
'status' => $response->status(),
'response' => $response->body(),
]);
Performance Monitoring
$this->logger->performance('slow_query', [
'query' => $sql,
'duration_ms' => $executionTime,
]);
Contextual Logging
$this->logger->info('User action', [
'user' => auth()->user()->toArray(),
'request' => request()->except(['password']),
]);
JavaScript Integration
Service Provider Hooks
AppServiceProvider:
public function boot() {
$this->app->bind(ApplicationLogger::class, function ($app) {
return new ApplicationLogger(
$app->make('config')->get('application_logger.dsn'),
$app->make('config')->get('application_logger.api_key')
);
});
}
Event Listeners
HandleExceptions:
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
public function __invoke(ExceptionEvent $event) {
$this->logger->error('Unhandled exception', [
'exception' => $event->getThrowable(),
'url' => $event->getRequest()->getUri(),
]);
}
Queue Failed Jobs
FailedJob:
public function handle(FailedJob $event) {
$this->logger->error('Job failed', [
'job' => $event->job,
'exception' => $event->exception,
]);
}
DSN/API Key Validation
dsn or api_key is invalid. Validate in config/packages/application_logger.yaml:
application_logger:
dsn: '%env(APPLICATION_LOGGER_DSN)%'
api_key: '%env(APPLICATION_LOGGER_API_KEY)%'
validate_credentials: true # Add this line
Connection refused or Invalid API key errors.Rate Limiting
async: true to queue logs:
application_logger:
async: true
failed_jobs table for queued-but-failed logs.Sensitive Data Leaks
mask: true for fields like emails).$this->logger->error('Login failed', [
'email' => ['value' => $email, 'mask' => true],
]);
Symfony Dependency Conflicts
Log facade, avoid mixing with this bundle’s logger. Use ApplicationLogger exclusively for error tracking.Enable Debug Mode
Set debug: true in config to log HTTP errors to Symfony’s profiler:
application_logger:
debug: true
Check HTTP Requests
Use strace or tcpdump to verify logs reach the endpoint:
strace -f -e trace=network php artisan tinker
Test Locally Mock the logger in tests:
$this->app->instance(ApplicationLogger::class, Mockery::mock(ApplicationLogger::class));
Custom Log Levels
Extend the bundle by adding a custom level (e.g., security):
$this->logger->custom('security', 'Unauthorized access', ['ip' => request()->ip()]);
Requires server-side support (contact maintainers).
Webhook Integration
Use Laravel’s queue:work to process logs and forward them to other services (e.g., Slack, Datadog):
$this->app->bind(ApplicationLogger::class, function ($app) {
$logger = new ApplicationLogger(...);
$logger->setWebhookHandler(function ($log) {
// Forward to your webhook
});
return $logger;
});
Breadcrumbs Add context to logs via middleware:
public function handle($request, Closure $next) {
$this->logger->addBreadcrumb('route', $request->route()->getName());
return $next($request);
}
How can I help you explore Laravel packages today?