Skip to content

This class can append log messages to ElasticSearch using Log4PHP.

Notifications You must be signed in to change notification settings

arfeen/log4php-elasticsearch-appender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Log4PHP ElasticSearch Appender

This class can append log messages to ElasticSearch using Log4PHP.

This class was initially published at PHP Classes.

This class can append log messages to ElasticSearch using Log4PHP.

It extends the Log4PHP LoggerAppender class to send HTTP requests to an ElasticSearch instance REST API to log event messages.

This class must be copied in [log4phproot]/appenders .

Below is the usage details. This appender will be configured in "Log4PHP" appender configurations.

Example configuration:

<?php

/* a sample configuration code for log4php. XML config can be used in same way. */

$configarray = array(
    'appenders' => array(
        'ElasticSearch' => array(
            'class' => 'LoggerAppenderElasticSearch',
            'layout' => array(
                'class' => 'LoggerLayoutPattern',
                'params' => array(
                    'conversionPattern' => json_encode(array(
                        'level' => "%p",
                        'ip' => "%X{ip}",
                        'action' => "%X{actor_id}",
                        'view' => "%X{view}",
                        'class_context' => "%X{class_context}",
                        "logtimestamp" => "%d{Y-m-d H:i:s}"
                    ))
                )
            ),
            'params' => array(
                'remoteHost' => 'localhost',
                'port' => '9200',
                'esIndex' => 'myindex',
                'esType' => 'mytype'
            ),
            'filters' => array(
                array(
                    'class' => 'LoggerFilterLevelRange',
                    'params' => array(
                        'levelMin' => 'info',
                        'levelMax' => 'fatal'
                    )
                )
            )
        )
    ),
    'rootLogger' => array(
        'level' => 'ALL',
        'appenders' => array(
            'ElasticSearch'
        )
    )
);



return $configarray;
?>

About

This class can append log messages to ElasticSearch using Log4PHP.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages