Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony Logger Client Laravel Package

dennisvanbeersel/symfony-logger-client

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require applogger/symfony-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        DennisVanBeersel\AppLoggerBundle\AppLoggerBundle::class => ['all' => true],
    ];
    
  2. Configuration Publish the default config:

    php artisan vendor:publish --tag=applogger-config
    

    Update .env with your APPLOGGER_API_KEY and APPLOGGER_APP_ID.

  3. First Use Case Trigger an exception (e.g., 1/0 in a route) and verify it appears in your AppLogger dashboard.


Implementation Patterns

Core Workflows

  1. Automatic Exception Capture

    • Uncaught exceptions are automatically logged to AppLogger via Symfony’s ErrorHandler.
    • Manual Logging: Use the AppLogger service to log custom events:
      $this->get('applogger')->log('custom_event', ['key' => 'value']);
      
  2. Monolog Integration

    • Configure Monolog handlers to forward logs to AppLogger:
      # config/packages/monolog.yaml
      monolog:
          handlers:
              applogger:
                  type: applogger
                  level: debug
      
  3. Middleware for Request Tracking

    • Use the AppLoggerMiddleware to attach request metadata (e.g., IP, user agent):
      // src/Kernel.php
      protected function build(RequestContext $requestContext)
      {
          $requestContext->addMiddleware(new AppLoggerMiddleware());
      }
      
  4. Performance Monitoring

    • Wrap critical sections with AppLoggerTimer:
      $timer = $this->get('applogger.timer')->start('database_query');
      // ... execute query ...
      $timer->stop();
      

Integration Tips

  • Laravel-Specific: Extend Symfony’s HttpKernel via Laravel’s Kernel class to leverage AppLogger’s middleware.
  • Queue Workers: Use the AppLogger service in queue jobs to log job execution:
    public function handle()
    {
        try {
            // Job logic
        } catch (\Exception $e) {
            $this->get('applogger')->logException($e);
        }
    }
    
  • Custom Context: Attach user-specific data (e.g., auth()->user()) via AppLoggerContext:
    $context = new AppLoggerContext();
    $context->setUserId(auth()->id());
    $this->get('applogger')->setContext($context);
    

Gotchas and Tips

Pitfalls

  1. API Key Leaks

    • Ensure APPLOGGER_API_KEY is never committed to version control. Use Laravel’s .env exclusions:
      echo ".env" >> .gitignore
      
    • Validate the key in config/packages/applogger.yaml:
      applogger:
          api_key: "%env(APPLOGGER_API_KEY)%"
          # Add validation: !php/const AppLoggerBundle\Validator\ApiKeyValidator::class
      
  2. Rate Limiting

    • AppLogger may throttle requests during spikes. Implement a fallback queue:
      $this->get('applogger')->setQueue('applogger');
      
    • Configure the queue in config/queue.php to use a resilient driver (e.g., database).
  3. Monolog Conflicts

    • If using multiple Monolog handlers, ensure applogger is last to avoid duplicate logs:
      handlers:
          main:
              type: stream
              path: "%kernel.logs_dir%/%kernel.environment%.log"
          applogger:
              type: applogger
              level: error
      
  4. Performance Overhead

    • Disable in production if unused:
      applogger:
          enabled: "%kernel.debug%"  # Only log in debug mode
      
    • For high-traffic apps, batch logs using AppLoggerBatcher:
      $batcher = $this->get('applogger.batcher');
      $batcher->addLog($log);
      $batcher->flush(); // Call periodically
      

Debugging

  • Log Levels: Use debug mode to test locally:
    applogger:
        level: debug
    
  • HTTP Debugging: Enable verbose logging for the HTTP client:
    applogger:
        http_client:
            debug: true
    
  • Check Dashboard: Verify logs appear in AppLogger’s "Logs" tab.

Extension Points

  1. Custom Log Formatters

    • Extend 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
      
  2. Webhook Events

    • Subscribe to AppLogger events (e.g., applogger.log.sent) via Symfony’s event dispatcher:
      $dispatcher->addListener('applogger.log.sent', function ($event) {
          // Custom logic on log submission
      });
      
  3. Database Fallback

    • Store logs locally if AppLogger is unavailable:
      applogger:
          fallback:
              enabled: true
              driver: database
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log