dulyanov/log4php-graylog2

Log4php appenders and layouts for compatibility with graylog2

Installs: 92

Dependents: 0

Stars: 10

Watchers: 3

Forks: 6

Open Issues: 1

Language: PHP

1.0.2 2015-04-30 15:12 UTC

README

About

Copyright (c) 2012-2014 Dmitriy Ulyanov

Here you can find 2 new appenders for log4php: LoggerAppenderAMQP and LoggerAppenderGraylog2. You can pass log messages to Graylog2 or AMQP (RabbitMQ for ex.) using it.

Appender LoggerAppenderGraylog2 can pass messages directly to Graylog2 server. Appender LoggerAppenderAMQP can pass messages to AMQP Server. In this case you can set up yours graylog2 to recieving messages from AMQP.

If you would like to pass messages in GELF format, use special layout: LoggerLayoutGelf

Installation

For composer users

  1. Add to your composer.json:

    {
        "require": {
            "dulyanov/log4php-graylog2": ">=1.0.0"
        },
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/d-ulyanov/log4php-graylog2.git"
            }
        ]
    }
    
  2. Run composer.phar update

For other users

  1. Set up your log4php config file (see exampleConfig.xml)
  2. Use your new logger:

require 'log4php/Logger.php';
require 'log4php-graylog2/src/main/php/bootstrap.php';

Configuration

XML

        
            
                
                
                
                
                
                
                
                
                
            
            
                
                
                
            
            
                
                
                
            
        

PHP

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

Usage

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

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