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

Will you push Laravel logs to Kafka?

藏色散人
Release: 2020-08-10 13:59:28
forward
3709 people have browsed it

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
Copy after login

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"
Copy after login

Get started

1. Modify the configuration file config/logging.php

return [
    'channels' => [
        // ...
        'kafka' => Hhxsv5\LKL\KafkaLogger::getDefinition(['topic' => env('LOG_KAFKA_TOPIC', 'laravel-logs')]),
    ],
];
Copy after login

2. Modify

.env

LOG_CHANNEL=kafka
LOG_KAFKA_BROKER_LIST=kafka:9092
LOG_KAFKA_TOPIC=laravel-logs
Copy after login

3. Okay Now, start logging

Log::info('用户登录', ['uid-hhxsv5']);
Copy after login
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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template