Giter Club home page Giter Club logo

slf4j-logback-zeromq's Introduction

Logback appender for ØMQ message transport layer

This project must be used with the Logback project in order to produce log messages over ZeroMQ messaging library.

This way, the application logs can be sent to remote systems / can be receive by remote systems in any language supported by ØMQ.

Installation

Requirements

Before installing and using this appender with Logback, you need to install ZeroMQ Java Binding library (2.1) on your system. This binding uses native library to work.

The ZeroMQ website is a great place to start installing the libraries, specially the Java binding page

If you want to develop or modify this plugin, I encourage you to read the ØMQ – The Guide which is very well documented.

You must download slf4j-api.jar, logback-core.jar and logback-classic.jar on their respective project pages SLF4J and Logback .

Installation

Put the following jar in the classpath of your Java application:

slf4j-logback-zeromq-0.0.1.jar

You must also put in the classpath the ØMQ Java binding compiled for your system:

jzmq-2.1.0.jar

Finally, put the SLF4J and Logback jars in the classpath:

slf4j-api-1.6.4.jar
logback-core-1.0.0.jar
logback-classic-1.0.0.jar

Configuration

The configuration of the ØMQ appender is done in the usual Logback configuration file

The appender must be declared in the logback*.xml file:

	<appender name="zeromq-bind" class="org.tlrx.logback.appender.ZMQSocketAppender">
		<!-- Define the ØMQ socket type -->
		<type>PUB</type>
		<!-- Only one of bind+connect must be declared -->
		<bind>tcp://*:9797</bind>
		<connect>tcp:localhost:9700</connect>
		<encoder>
			<!-- Message format -->
			<pattern>%-5level %logger{26} - %msg</pattern>
		</encoder>
	</appender>

Where:

Property Description
<type> Define the ØMQ socket type, value can be: PUB, SUB, REQ, XREQ. The default value is set to PUB
<bind> The ØMQ socket will connect to the given address using bind method. Can be used only if socket is PUB or SUB type
<connect> The ØMQ socket will connect to the given address using connect method
<pattern> The pattern defines the format of the ØMQ message that will be sent by the appender. The format used the same PatternLayout of the default Logback ConsoleAppender
<highWaterMark> A high water mark for the socket, after which messages will be discarded (if they’re not sent). This prevents infinite buffering (and ergo infinite RAM use) if the thing you are sending to is down. Defaults to 10000 messages

Examples of use

Publish log messages over TCP

Description

In this example, the log messages will be encapsualted in a ØMQ message and published by the appender on a given address.

Remote applications (subscribers) can connect to the ØMQ publisher socket and start receiving messages. The subscribers can also filter by log level the messages they want to receive.

Configuration

The configuration of the Logback appender defines a Publisher socket:

 <appender name="zeromq-bind" class="org.tlrx.logback.appender.ZMQSocketAppender">
        <type>PUB</type>
        <bind>tcp://*:9797</bind>
        <encoder>
            <pattern>%-5level %logger{26} - %msg</pattern>
        </encoder>
    </appender>

At runtime

Once started, the appender sends log messages like this:

DEBUG org.eclipse.jetty.util.log - doSelect true

Remote application can now connect to the publisher address to receive log messages. The ZMQSocketAppenderTest class gives an example of how to connect to the publisher and receive only ERROR messages.

If no subscribers is connected, the publisher will drop the message (this is a default ØMQ behavior).

Index log messages in Elasticsearch

Description

In this example, the ØMQ appender is configured to send log messages to the ØMQ transport plugin for Elasticsearch

This way, it is possible to index and search log messages with Elasticsearch features.

Configuration

The configuration of the Logback appender defines a XREQ socket:

<configuration>
...
    <appender name="zeromq-connect" class="org.tlrx.logback.appender.ZMQSocketAppender">
        <type>XREQ</type>
        <connect>tcp://localhost:9700</connect>
        <encoder>
            <pattern>POST|/logs/log/|{"origin":"my_app", "level":"%-5level", "message":"%msg", "thread":"%thread", "date":"%d{HH:mm:ss.SSS}", "logger":"%logger{26}", "exception":"%ex"}</pattern>
        </encoder>
    </appender>
...
</configuration>

The ØMQ transport plugin for Elasticsearch listen by default on the <tcp://*:9700> address.

In this configuration, the pattern for log messages reflects the format expected by the Elasticsearch plugin.

At runtime

Once started, the appender sends log messages to the Elasticsearch plugin, which index them in the logs index.

slf4j-logback-zeromq's People

Contributors

bobtfish avatar tlrx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slf4j-logback-zeromq's Issues

Escape char for JSON

Many char must be escaped before being sent w/ JSON.

It will avoid parsing issues on ES side.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.