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
Use the extension packagelaravel-kafka-logger Push Laravel’s logs to Kafka is then consumed, stored, and presented by ELK.
Dependencies
>=4.0.0 |
|
rdkafkagit 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.Installgit 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"
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 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-logs
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

Laravel schedule task run unresponsive troubleshooting When using Laravel's schedule task scheduling, many developers will encounter this problem: schedule:run...

The method of handling Laravel's email failure to send verification code is to use Laravel...

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

Confusion and the cause of choosing from PHP to Go Recently, I accidentally learned about the salary of colleagues in other positions such as Android and Embedded C in the company, and found that they are more...

The impact of sharing of Redis connections in Laravel framework and select methods When using Laravel framework and Redis, developers may encounter a problem: through configuration...

Custom tenant database connection in Laravel multi-tenant extension package stancl/tenancy When building multi-tenant applications using Laravel multi-tenant extension package stancl/tenancy,...
