Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Adventures in Java

fyi, I've already broken this out into a distinct repo here This is where I'm documenting all the shit I went through in learning enough java to get this zeromq appender modified.


I'm currently modifying the logcentric ZMQAppender to add some functionality:

  • configurable socket pair type (push and pub right now)
  • configurable bind vs. connect
  • topics on pub sockets
  • socket identity (not critical right now)

Eventually I want to add properties that add additional fields to the json that gets sent. I also want to make the endpoint accept multiple hosts.

Last step is to break everything OUT of logcentric and into a standalone project. All I need is a ZeroMQ appender that spits out JSON.

Gotchas I've run into

  • log4j doesn't like underscores in property names
  • evidently the order in which you compare strings with .equals matters and can throw an NPE with the wrong order

Building the test sender

cd foo; javac -cp ../classes/log4j-1.2.16.jar cd ..; jar cvf foo.jar foo/*.class

local receiver

Just need something listening with the right socket pair and port

other shit

Building jzmq on OSX sucks. Right now I'm compiling logcentric locally and copying the artifact up to a remote linux host where I'm running the sender.

the code to build the jar is here:

It works fairly well right now, surprisingly.... could use some help ;)

# The Root uses the Console
# Setup the Console
log4j.appender.Console.layout.ConversionPattern=[%d{dd MMM yyyy HH:mm:ss.SSS}] [%p.%c] %m%n
package foo;
import org.apache.log4j.Logger;
import java.sql.SQLException;
import java.util.*;
public class Log4jExample {
/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(
public static void main(String[] args)
throws IOException,SQLException{
log.debug("Hello this is an debug message");"Hello this is an info message");
java -cp foo.jar:classes/log4j-1.2.16.jar:classes/logcentric-0.0.1.jar:classes/zmq.jar:classes/gson-1.7.1.jar -Dlog4j.configuration=file:classes/ -Djava.library.path=/usr/local/lib foo.Log4jExample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment