Home > Article > PHP Framework > Will you push Laravel logs to Kafka?
The following tutorial column will introduce you to the method of pushing Laravel logs to Kafka. I hope it will be helpful to friends in need!
Laravel Kafka Logger
>=4.0.0 |
|
git clone --depth 1 https://github.com/edenhill/librdkafka.git /tmp/librdkafka && cd /tmp/librdkafka && ./configure && make -j$(nproc) && make install && rm -rf /tmp/librdkafka pecl install rdkafka
laravel-kafka-logger
# Laravel 5.x composer require "hhxsv5/laravel-kafka-logger:~1.0.0" # Laravel 6.x & 7.x composer require "hhxsv5/laravel-kafka-logger:~2.0.0"Get started
1. Modify the configuration file
config/logging.php
return [ 'channels' => [ // ... 'kafka' => Hhxsv5\LKL\KafkaLogger::getDefinition(['topic' => env('LOG_KAFKA_TOPIC', 'laravel-logs')]), ], ];
.env
LOG_CHANNEL=kafka LOG_KAFKA_BROKER_LIST=kafka:9092 LOG_KAFKA_TOPIC=laravel-logs3. Okay Now, start logging
Log::info('用户登录', ['uid-hhxsv5']);
Note:
Under what circumstances do you need to use kafka for log storage?
First, it is convenient to collect logs in a centralized manner, and there is no need to install a client on each machine to collect logs; Second, Kafka writes asynchronously and has higher performance.
The above is the detailed content of Will you push Laravel logs to Kafka?. For more information, please follow other related articles on the PHP Chinese website!