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

Ai Monolog Laravel Package

aimeos/ai-monolog

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require aimeos/ai-monolog
    

    Ensure aimeos/aimeos-laravel is also installed (core dependency).

  2. Configuration: Add to config/logging.php under channels:

    'aimeos' => [
        'driver' => 'custom',
        'via' => \Aimeos\AI\Monolog\Handler::class,
        'config' => [
            'client' => [
                'host' => env('AIMEOS_HOST', 'localhost'),
                'port' => env('AIMEOS_PORT', 8080),
            ],
            'logger' => [
                'name' => 'aimeos',
                'level' => env('AIMEOS_LOG_LEVEL', \Monolog\Logger::DEBUG),
            ],
        ],
    ],
    
  3. First Use Case: Log a debug message to Aimeos:

    \Log::channel('aimeos')->debug('User viewed product', [
        'product_id' => 123,
        'user_id' => auth()->id(),
    ]);
    

Implementation Patterns

Workflows

  1. Contextual Logging: Attach Aimeos-specific metadata (e.g., session, product, or order data) to logs:

    $context = [
        'aimeos' => [
            'session' => session()->all(),
            'product' => $product->getId(),
        ],
    ];
    \Log::channel('aimeos')->info('Order processed', $context);
    
  2. Error Handling: Catch exceptions and log them with Aimeos:

    try {
        // Risky operation
    } catch (\Exception $e) {
        \Log::channel('aimeos')->error('Payment failed', [
            'exception' => $e->getMessage(),
            'trace' => $e->getTraceAsString(),
            'order_id' => $order->getId(),
        ]);
    }
    
  3. Performance Tracking: Log request durations with timestamps:

    $start = microtime(true);
    // ... business logic ...
    \Log::channel('aimeos')->debug('Request completed', [
        'duration_ms' => (microtime(true) - $start) * 1000,
        'route' => request()->route()->getName(),
    ]);
    

Integration Tips

  • Middleware: Use the channel in middleware to log API requests:

    public function handle($request, Closure $next) {
        \Log::channel('aimeos')->info('API request', [
            'method' => $request->method(),
            'path' => $request->path(),
            'ip' => $request->ip(),
        ]);
        return $next($request);
    }
    
  • Events: Log custom events (e.g., order.created):

    event(new OrderCreated($order));
    // In EventServiceProvider:
    protected $listen = [
        OrderCreated::class => [\App\Listeners\LogOrderEvent::class],
    ];
    
  • Queue Jobs: Log job execution in handle():

    public function handle() {
        \Log::channel('aimeos')->debug('Job started', ['job' => $this->job]);
        // ... job logic ...
        \Log::channel('aimeos')->debug('Job completed');
    }
    

Gotchas and Tips

Pitfalls

  1. Connection Issues:

    • If Aimeos client is unreachable, logs will silently fail. Add a fallback:
      'config' => [
          'client' => [...],
          'fallback' => true, // Logs to default channel if Aimeos fails
      ],
      
  2. Serialization:

    • Complex objects (e.g., Eloquent models) may not serialize cleanly. Use ->toArray() or custom handlers:
      \Log::channel('aimeos')->debug('Product', [
          'data' => $product->toArray(),
      ]);
      
  3. Performance Overhead:

    • Avoid logging in tight loops (e.g., product iteration). Batch logs or use lower verbosity.

Debugging

  • Check Log Level: Ensure AIMEOS_LOG_LEVEL matches your needs (e.g., DEBUG for development, INFO for production).
  • Aimeos Client Logs: Enable debug for the Aimeos client in config/aimeos.php:
    'client' => [
        'debug' => env('AIMEOS_DEBUG', false),
    ],
    
  • Handler Validation: Verify the handler is registered:
    php artisan config:clear
    

Extension Points

  1. Custom Handlers: Extend \Aimeos\AI\Monolog\Handler to add pre-processing:

    class CustomHandler extends \Aimeos\AI\Monolog\Handler {
        protected function getContext($record) {
            $context = parent::getContext($record);
            $context['custom'] = 'value';
            return $context;
        }
    }
    
  2. Dynamic Channels: Create dynamic channels for different Aimeos services (e.g., aimeos.catalog, aimeos.order):

    $channel = \Log::channel('aimeos')->withContext(['service' => 'catalog']);
    
  3. Log Enrichment: Use Monolog processors to enrich logs before sending:

    'config' => [
        'processors' => [
            new \Monolog\Processor\UidProcessor(),
            new \Monolog\Processor\MemoryUsageProcessor(),
        ],
    ],
    
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle