Home  >  Article  >  PHP Framework  >  Will you push Laravel logs to Kafka?

Will you push Laravel logs to Kafka?

藏色散人
藏色散人forward
2020-08-10 13:59:193648browse

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!

Will you push Laravel logs to Kafka?Laravel Kafka Logger

Use the extension packagelaravel-kafka-logger Push Laravel’s logs to Kafka is then consumed, stored, and presented by ELK.

Requirements

DependenciesRequirementsphp-rdkafka ##Dependency installation
>=4.0.0
1.Install

rdkafka
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

2.Install

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')]),
    ],
];

2. Modify

.env

LOG_CHANNEL=kafka
LOG_KAFKA_BROKER_LIST=kafka:9092
LOG_KAFKA_TOPIC=laravel-logs

3. 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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete