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

Logger Laravel Package

fluent/logger

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The fluent/logger package is a lightweight, direct PHP-to-Fluentd logging solution, ideal for applications requiring structured logging with minimal overhead. It fits well in architectures where:
    • Logs must be aggregated centrally via Fluentd (e.g., microservices, monolithic apps with distributed components).
    • Real-time log processing is critical (e.g., observability, debugging, or compliance).
    • Monolog or other abstraction layers are unnecessary, and direct Fluentd integration is preferred.
  • Anti-Patterns: Avoid if:
    • The team requires buffering/retry logic (PHP’s lack of threading necessitates a local Fluentd proxy).
    • Multi-process safety is critical (e.g., CLI workers, cron jobs) without a proxy.
    • PSR-3 compliance is a hard requirement (this library predates PSR-3 and lacks adapter support).

Integration Feasibility

  • PHP Version: Supports PHP 5.6+, but PHP 7.4+ is recommended for modern Laravel (8.x/9.x/10.x) to avoid deprecated features (e.g., create_function, weak typing).
  • Fluentd Dependency: Requires Fluentd v0.9.20+ (or later). Modern deployments (e.g., Kubernetes, Docker) may need sidecar proxies for local buffering.
  • Laravel Compatibility:
    • No native Laravel integration: Must be manually instantiated (e.g., in AppServiceProvider or a dedicated logger service).
    • Conflict Risk: Low if not replacing Laravel’s default Monolog; high if mixing with other loggers (e.g., stack handlers).
    • Queue Integration: Fluentd’s TCP/UDP transport is not queue-aware, so failed logs may be lost without a proxy.

Technical Risk

Risk Area Severity Mitigation Strategy
Deprecated Code High Replace FluentLogger with a wrapper or fork to modernize (e.g., add PSR-3 support).
No Buffering High Deploy a local Fluentd proxy (as recommended) to handle retries/buffering.
Thread Safety Medium Ensure single-process usage or use a proxy.
Lack of Maintenance Medium Fork or extend for critical features (e.g., TLS, async support).
Performance Low Benchmark against Monolog + Fluentd handler.

Key Questions

  1. Why Fluentd?
    • Is Fluentd already in use? If not, justify the overhead (e.g., vs. ELK, Loki, or S3 logs).
  2. Proxy Requirement
    • Can a local Fluentd proxy (e.g., Docker sidecar) be deployed per service, or is central aggregation mandatory?
  3. Error Handling
    • How will log failures be monitored? (No built-in retry or dead-letter queue.)
  4. Structured Logging
    • Does the app need JSON/key-value pairs, or is post("tag", ["key" => "value"]) sufficient?
  5. Alternatives
    • Compare with:
      • monolog/handler-fluentd (PSR-3 compliant, but slower).
      • symfony/var-dumper + custom Fluentd client.
      • Laravel’s built-in Log::channel() with a Fluentd handler.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Pros:
      • Lightweight (~50KB) vs. Monolog (~1MB).
      • Direct Fluentd integration avoids serialization overhead.
    • Cons:
      • No Laravel-specific features (e.g., Log::stack(), context binding).
      • Requires manual setup (e.g., no config/logging.php support).
  • Recommended Stack:
    Laravel 10.x
    ├── fluent/logger (v1.0.1, forked for PHP 8.x)
    ├── fluentd-proxy (Docker sidecar, v1.15+)
    └── central Fluentd (v1.16+ with `out_elasticsearch`/`out_s3`)
    

Migration Path

  1. Phase 1: Proof of Concept
    • Replace a single logger (e.g., Log::debug()) with FluentLogger in a non-critical service.
    • Test with a local Fluentd proxy (e.g., fluent/fluentd:latest).
    • Validate log structure and latency.
  2. Phase 2: Full Integration
    • Option A: Fork the package to add:
      • PHP 8.x support.
      • PSR-3 adapter for Laravel’s Log::channel().
      • Async transport (e.g., reactphp or pthreads).
    • Option B: Use a wrapper class to bridge FluentLogger with Laravel’s LogManager:
      // app/Providers/AppServiceProvider.php
      public function register()
      {
          Log::extend('fluent', function ($app) {
              return new class {
                  public function __invoke(array $config)
                  {
                      $logger = new Fluent\Logger\FluentLogger(
                          $config['host'] ?? 'localhost',
                          $config['port'] ?? 24224
                      );
                      return new LaravelFluentHandler($logger);
                  }
              };
          });
      }
      
  3. Phase 3: Proxy Deployment
    • Deploy a Fluentd proxy per service (e.g., Kubernetes Sidecar or Docker network_mode: host).
    • Configure in_forward to buffer logs locally before forwarding to central Fluentd.

Compatibility

Component Compatibility Notes
PHP 8.x ❌ Not natively supported. Requires fork or polyfills (e.g., ext-json for json_encode).
Laravel 8+ ✅ Works, but lacks Log::stack() or context binding.
Fluentd 1.x ✅ Tested with v0.9.20+. Modern v1.x may need config tweaks (e.g., in_forward buffer).
Docker/K8s ✅ Proxy pattern works well in containers.
Windows ❌ Unlikely to work (Fluentd is Unix-focused).

Sequencing

  1. Prerequisite: Deploy a central Fluentd instance (or use an existing one).
  2. Step 1: Add the package via Composer (with a fork if PHP 8.x is needed).
  3. Step 2: Configure a local Fluentd proxy for each service.
  4. Step 3: Replace Log:: calls in critical paths (e.g., API controllers, jobs).
  5. Step 4: Monitor log delivery with Fluentd’s out_exec (e.g., tail -f /var/log/fluent.log).
  6. Step 5: Gradually migrate remaining loggers.

Operational Impact

Maintenance

  • Pros:
    • Minimal moving parts (no Monolog overhead).
    • Direct control over log format (no serialization/deserialization).
  • Cons:
    • No official updates since 2017. Maintenance falls to the team.
    • Debugging: Log failures require checking:
      1. PHP process → Fluentd proxy connection.
      2. Proxy → Central Fluentd connection.
      3. Central Fluentd → Output (e.g., Elasticsearch).
    • Tooling: Lack of built-in health checks (e.g., no logger->ping()).

Support

  • Community: Limited (218 stars, last release 6 years ago). Issues may go unanswered.
  • Workarounds:
    • Use Monolog + FluentdHandler for PSR-3 compliance.
    • Extend the library to add:
      • Metrics (e.g., prometheus exporter for log latency).
      • TLS support (Fluentd’s in_forward supports it, but PHP client does not).
  • Vendor Lock-in: Low (Fluentd is a standard; switching clients is easier than switching aggregators).

Scaling

  • Horizontal Scaling:
    • Stateless: The PHP client is stateless; scaling apps won’t overload Fluentd if proxies are sized correctly.
    • Proxy Bottleneck: Local Fluentd proxies must be scaled with app instances (e.g., 1 proxy per pod in K8s).
  • Vertical Scaling:
    • Fluentd proxies can be tuned with:
      • <buffer> settings in fluent.conf (e.g., flush_interval, chunk_limit).
      • in_forward buffer paths (e.g., /var/log/fluent-buffer).
  • Load Testing:
    • Simulate high-volume
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.
andydefer/laravel-actions
aimeos/prisma
besmartand-pro/php-quality-config
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