PHP code example of tasmidur / kafka-monolog-handler

1. Go to this page and download the library: Download tasmidur/kafka-monolog-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tasmidur / kafka-monolog-handler example snippets


return [
    'channels' => [
        // ...
       'kafka' => \Tasmidur\KafkaMonologHandler\KafkaLogger::getInstance(
            topicName: env('KAFKA_LOG_FILE_TOPIC', 'laravel_logs'),
            brokers: env('KAFKA_LOG_BROKERS')
        ),
    ],
];

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