dennisvanbeersel/symfony-logger-client
Installation
composer require applogger/symfony-bundle
Add to config/bundles.php:
return [
// ...
DennisVanBeersel\AppLoggerBundle\AppLoggerBundle::class => ['all' => true],
];
Configuration Publish the default config:
php artisan vendor:publish --tag=applogger-config
Update .env with your APPLOGGER_API_KEY and APPLOGGER_APP_ID.
First Use Case
Trigger an exception (e.g., 1/0 in a route) and verify it appears in your AppLogger dashboard.
Automatic Exception Capture
ErrorHandler.AppLogger service to log custom events:
$this->get('applogger')->log('custom_event', ['key' => 'value']);
Monolog Integration
# config/packages/monolog.yaml
monolog:
handlers:
applogger:
type: applogger
level: debug
Middleware for Request Tracking
AppLoggerMiddleware to attach request metadata (e.g., IP, user agent):
// src/Kernel.php
protected function build(RequestContext $requestContext)
{
$requestContext->addMiddleware(new AppLoggerMiddleware());
}
Performance Monitoring
AppLoggerTimer:
$timer = $this->get('applogger.timer')->start('database_query');
// ... execute query ...
$timer->stop();
HttpKernel via Laravel’s Kernel class to leverage AppLogger’s middleware.AppLogger service in queue jobs to log job execution:
public function handle()
{
try {
// Job logic
} catch (\Exception $e) {
$this->get('applogger')->logException($e);
}
}
auth()->user()) via AppLoggerContext:
$context = new AppLoggerContext();
$context->setUserId(auth()->id());
$this->get('applogger')->setContext($context);
API Key Leaks
APPLOGGER_API_KEY is never committed to version control. Use Laravel’s .env exclusions:
echo ".env" >> .gitignore
config/packages/applogger.yaml:
applogger:
api_key: "%env(APPLOGGER_API_KEY)%"
# Add validation: !php/const AppLoggerBundle\Validator\ApiKeyValidator::class
Rate Limiting
$this->get('applogger')->setQueue('applogger');
config/queue.php to use a resilient driver (e.g., database).Monolog Conflicts
applogger is last to avoid duplicate logs:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
applogger:
type: applogger
level: error
Performance Overhead
applogger:
enabled: "%kernel.debug%" # Only log in debug mode
AppLoggerBatcher:
$batcher = $this->get('applogger.batcher');
$batcher->addLog($log);
$batcher->flush(); // Call periodically
debug mode to test locally:
applogger:
level: debug
applogger:
http_client:
debug: true
Custom Log Formatters
AppLoggerFormatter to modify payloads:
class CustomFormatter extends AppLoggerFormatter
{
public function format(array $record): array
{
$record['custom_field'] = 'value';
return parent::format($record);
}
}
Register in services.yaml:
services:
AppLoggerBundle\Formatter\AppLoggerFormatter:
class: App\CustomFormatter
Webhook Events
applogger.log.sent) via Symfony’s event dispatcher:
$dispatcher->addListener('applogger.log.sent', function ($event) {
// Custom logic on log submission
});
Database Fallback
applogger:
fallback:
enabled: true
driver: database
How can I help you explore Laravel packages today?