PHP code example of dulyanov / log4php-graylog2

1. Go to this page and download the library: Download dulyanov/log4php-graylog2 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/ */

    

dulyanov / log4php-graylog2 example snippets


  

array(
    'rootLogger' => array(
        'appenders' => array('MyAMQPAppender', 'MyGraylog2Appender')
    ),
    'appenders' => array(
        'MyAMQPAppender' => array(
            'class' => 'LoggerAppenderAMQP',
            'params' => array(
                'host' => 'example.com',
                'port' => 5672,
                'vhost' => '/logs',
                'login' => 'my_login',
                'password' => 'my_secret_password',
                'exchangeName' => 'my_exchange',
                'routingKey' => 'php_application',
                'contentType' => 'application/json'
            ),
            'layout' => array(
                'class' => 'LoggerLayoutGelf'
            )
        ),
        'MyGraylog2Appender' => array(
            'class' => 'LoggerAppenderGraylog2',
            'params' => array(
                'host' => '192.168.1.123',
                'port' => 12201
            ),
            'layout' => array(
                'class' => 'LoggerLayoutGelf'
            )
        ),
    ),
);

Logger::configure('exampleConfig.xml', 'LoggerConfigurationAdapterXML');

$myLogger = Logger::getLogger('MyLogger');
$myLogger->debug("Hello world!");