alexusmai/kafka-log-driver

Laravel, log driver for Kafka

2.0 2023-08-08 09:14 UTC

This package is auto-updated.

Last update: 2024-04-12 04:48:59 UTC


README

Requirements:

  • PHP 8.1, 8.2
  • Laravel 9, 10
  • rdkafka php extension v.6
sudo pecl install rdkafka

Add the following line to your php.ini file:

extension=rdkafka.so

Installation

You can install the package via composer:

composer require alexusmai/kafka-log-driver

For Laravel 9

composer require alexusmai/kafka-log-driver:1.0

You can publish the config file with:

php artisan vendor:publish --tag="kafka-log-driver-config"

This is the contents of the published config file (kafka_log.php):

return [
    // topic name
    'topic'         => env('KAFKA_LOG_FILE_TOPIC'),
    // kafka brokers - "10.0.0.1,10.0.0.2"
    'brokers'       => env('KAFKA_LOG_BROKERS'),
    // timeout - ms
    'flush_timeout' => env('KAFKA_LOG_FLUSH_TIMEOUT', 100)
];

Usage

Add to .env

KAFKA_LOG_FILE_TOPIC=
KAFKA_LOG_BROKERS=
// if you want to change the default value (100 ms)
KAFKA_LOG_FLUSH_TIMEOUT=

Add to config/logging.php

'channels' => [
    ...
    'kafka' => [
        'driver' => 'custom',
        'via' => Alexusmai\KafkaLogDriver\KafkaLogger::class,
    ],
    ...
],

License

The MIT License (MIT). Please see License File for more information.