tasmidur / kafka-monolog-handler
Kafka Monolog Handler is used for pushing laravel log into the Kafka message broker
Installs: 2 085
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^8.0
- illuminate/config: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
- mateusjunges/laravel-kafka: ^1.8
This package is auto-updated.
Last update: 2024-11-25 15:49:39 UTC
README
The "kafka-monolog-handler" package is a package for Laravel framework. This package allows you to send your Laravel application's log messages to a Kafka server using Monolog, a popular logging library for PHP.
The package provides a handler for Monolog that sends log messages to a Kafka topic. The package also includes a config file, where you can specify the host and port of your Kafka server, as well as the topic to which the log messages should be sent
Requirements
This package also requires the rdkafka php extension, which you can install by following this documentation
Install
Install kafka-monolog-handler.
composer require tasmidur/kafka-monolog-handler
Get Started
1.Modify config/logging.php
.
Without Kafka SASL Config
return [ 'channels' => [ // ... 'kafka' => \Tasmidur\KafkaMonologHandler\KafkaLogger::getInstance( topicName: env('KAFKA_LOG_FILE_TOPIC', 'laravel_logs'), brokers: env('KAFKA_LOG_BROKERS') ), ], ];
With Kafka SASL Config and Log Formatter like ElasticsearchFormatter
return [ 'channels' => [ // ... 'kafka' => \Tasmidur\KafkaLogger\KafkaLogger::getInstance( topicName: env('KAFKA_LOG_FILE_TOPIC', 'system_logs'), brokers: env('KAFKA_BROKERS'), options: [ 'is_sasl_apply' => env('IS_SASL_APPLY'), //true = applied or false= not apply 'sasl_config' => [ 'username' => env('KAFKA_BROKER_USERNAME'), 'password' => env('KAFKA_BROKER_PASSWORD'), 'mechanisms' => env('KAFKA_BROKER_MECHANISMS'), 'security_protocol' => env('KAFKA_BROKER_SECURITY_PROTOCOL') ], 'formatter' => new ElasticsearchFormatter( index: env('KAFKA_LOG_FILE_TOPIC', 'laravel_logs'), type: "_doc") ] ), ], ];
2.Modify .env
.
LOG_CHANNEL=kafka
KAFKA_BROKERS=kafka:9092,kafka:9093
KAFKA_LOG_FILE_TOPIC=laravel-logs
IS_SASL_APPLY=false
KAFKA_BROKER_USERNAME=username
KAFKA_BROKER_PASSWORD=password
KAFKA_BROKER_MECHANISMS=SCRAM-SHA-512
KAFKA_BROKER_SECURITY_PROTOCOL=SASL_SSL