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

Ovh Logs Bundle Laravel Package

chaplean/ovh-logs-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

To integrate this package into a Laravel project, start by installing it via Composer:

composer require vendor/package-name

Publish the configuration files to customize the package settings:

php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider" --tag="config"

The package now supports OVH Graylog out-of-the-box. Ensure your config/gelf.php (or equivalent) includes the new header configuration for GELF requests:

'headers' => [
    'X-Graylog-Header' => 'your-custom-value', // Example OVH-specific header
],

For parameter-based configuration, define values in config/parameters.yml (or your Laravel env equivalent) and reference them in the config file.

First use case: Send a GELF-formatted log to Graylog (including OVH-compatible headers):

use Vendor\PackageName\Facades\GelfLogger;

GelfLogger::log('Your log message', ['context' => 'data']);

Implementation Patterns

Configuration Workflows

  1. Centralized Config: Use config/gelf.php for static settings (e.g., Graylog host, port).
  2. Dynamic Parameters: Store sensitive/environment-specific values (e.g., OVH API keys) in parameters.yml or .env and reference them via:
    'headers' => [
        'X-Graylog-Header' => env('GRAYLOG_OVH_HEADER'),
    ],
    
  3. Environment-Specific Overrides: Extend the config in config/gelf.php per environment (e.g., config/gelf-local.php).

Logging Patterns

  • Structured Logging: Pass associative arrays for context:
    GelfLogger::error('Failed to process order', [
        'order_id' => 123,
        'user_id' => 456,
        'exception' => $e,
    ]);
    
  • Middleware Integration: Use the package in Laravel middleware to log HTTP requests/responses:
    public function handle($request, Closure $next) {
        $response = $next($request);
        GelfLogger::info('Request completed', [
            'path' => $request->path(),
            'status' => $response->status(),
        ]);
        return $response;
    }
    

OVH Graylog Integration

  • Headers: The new headers config key enables OVH-specific Graylog features. Example:
    'headers' => [
        'X-Graylog-Ext-Msg' => 'custom-ovh-metadata',
    ],
    
  • Validation: Ensure your Graylog OVH instance expects these headers to avoid logging failures.

Gotchas and Tips

Configuration Pitfalls

  1. Missing Headers: If using OVH Graylog, omit or misconfigure the headers key will result in rejected logs. Validate with:
    curl -X POST -H "X-Graylog-Header: your-value" http://graylog:12201/gelf
    
  2. Parameter Resolution: Values in parameters.yml must match the config key names exactly. Use php artisan config:clear after updates to reload.

Debugging

  • Log Delivery Issues: Check Graylog’s HTTP input for rejected messages (filter by gelf).
  • Environment Mismatch: Ensure APP_ENV aligns with your published config (e.g., gelf-local.php for development).
  • Facades vs. Direct Usage: Prefer dependency injection for testing:
    public function __construct(\Vendor\PackageName\GelfLogger $logger) {
        $this->logger = $logger;
    }
    

Extension Points

  1. Custom Headers: Extend the headers array dynamically via service providers:
    GelfLogger::extend(function ($app) {
        $app['gelf.headers']['X-Custom'] = 'dynamic-value';
    });
    
  2. Log Formatting: Override the default GELF formatter by binding a custom class to gelf.formatter.
  3. Queue Integration: For high-volume logs, wrap the logger in a queue job to avoid blocking:
    use Vendor\PackageName\Jobs\LogToGelf;
    
    LogToGelf::dispatch('Message', ['data'])->onQueue('logs');
    

OVH-Specific Tips

  • Rate Limiting: OVH Graylog may throttle requests. Implement exponential backoff in your logger:
    try {
        GelfLogger::log($message);
    } catch (\GuzzleHttp\Exception\RequestException $e) {
        if ($e->getCode() === 429) {
            sleep(2 ** $retryCount++);
            retry();
        }
    }
    
  • Metadata: Use Graylog’s short_message and full_message fields to separate OVH-specific metadata from logs.
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware