Weave Code
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

Logentries Bundle Laravel Package

babzich/logentries-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require babzich/logentries-bundle
    

    Add to AppKernel.php:

    new Bab\LogentriesBundle\BabLogentriesBundle(),
    
  2. Configuration: Add to config/packages/bab_logentries.yaml (create if missing):

    bab_logentries:
        token: "%env(LOGENTRIES_TOKEN)%"
        host: "%env(LOGENTRIES_HOST)%"  # Optional (defaults to logentries.com)
    
  3. First Use Case: Inject the logger in a service/controller:

    use Psr\Log\LoggerInterface;
    
    class MyController
    {
        public function __construct(private LoggerInterface $logger)
        {
        }
    
        public function index()
        {
            $this->logger->info('Test log message');
        }
    }
    

Implementation Patterns

Common Workflows

  1. Logging in Controllers/Commands:

    $this->logger->debug('Debug info', ['context' => 'key']);
    $this->logger->error('Error occurred', ['exception' => $e]);
    
  2. Dynamic Log Levels: Use env() or config to toggle log levels:

    bab_logentries:
        level: "%env(LOG_LEVEL)%"  # e.g., "debug", "info"
    
  3. Tagging Logs: Add tags via context:

    $this->logger->info('User action', ['tags' => ['user', 'auth']]);
    
  4. Integration with Monolog: Extend the handler for custom logic:

    $handler = new \LogEntries\Handler(
        $this->get('bab_logentries.token'),
        $this->get('bab_logentries.host')
    );
    $handler->setFormatter(new \Monolog\Formatter\LineFormatter());
    

Best Practices

  • Environment-Specific Configs: Use %env() for tokens/hosts to avoid hardcoding.
  • Log Rotation: Combine with Monolog’s RotatingFileHandler for local fallback.
  • Structured Logging: Leverage context arrays for metadata (e.g., ['user_id' => 123]).

Gotchas and Tips

Pitfalls

  1. Token/Host Validation:

    • No built-in validation for LOGENTRIES_TOKEN/HOST. Validate in config/validator.yaml:
      services:
          Bab\LogentriesBundle\Validator\LogentriesValidator:
              arguments: ["%env(LOGENTRIES_TOKEN)%"]
      
  2. Dependency Conflicts:

    • The package pins logentries/logentries-monolog-handler to dev-master. Pin to a stable version in composer.json:
      "require": {
          "logentries/logentries-monolog-handler": "^1.0"
      }
      
  3. Network Dependencies:

    • Logs may queue locally if Logentries is unreachable. Use Monolog’s BufferHandler for resilience:
      $handler = new \Monolog\Handler\BufferHandler(new \LogEntries\Handler($token));
      

Debugging Tips

  • Check Handler Status:
    $handler = $this->logger->getHandlers()[0];
    if (!$handler->isHandling()) {
        $this->logger->error('Logentries handler inactive!');
    }
    
  • Logentries API Limits: Monitor rate limits via Logentries dashboard. Throttle logs if needed:
    $handler->setBatchMode(100); // Batch 100 logs per request
    

Extension Points

  1. Custom Formatter: Override the default formatter in services.yaml:

    services:
        Bab\LogentriesBundle\Handler\LogEntriesHandler:
            arguments:
                - "%env(LOGENTRIES_TOKEN)%"
                - "%env(LOGENTRIES_HOST)%"
            calls:
                - [setFormatter, ["@custom_logentries_formatter"]]
    
  2. Pre-Process Logs: Use a Monolog processor:

    $processor = new \Monolog\Processor\UidProcessor();
    $this->logger->pushProcessor($processor);
    
  3. Fallback Handlers: Chain with other handlers (e.g., StreamHandler):

    $this->logger->pushHandler(
        new \Monolog\Handler\StreamHandler('/var/log/app.log', Monolog\Logger::DEBUG)
    );
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor