public
Created

Adventures in Java

  • Download Gist
an-readme.md
Markdown

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.

Needs

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 Log4jExample.java 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:

https://github.com/lusis/logcentric/tree/idontknowjava

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

log4j.properties
INI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# The Root uses the Console
log4j.rootCategory=TRACE,Console,Zmq
 
 
# Setup the Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Threshold=TRACE
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%d{dd MMM yyyy HH:mm:ss.SSS}] [%p.%c] %m%n
 
log4j.appender.Zmq=com.y1ban.logcentric.publisher.ZMQAppender
log4j.appender.Zmq.Threshold=DEBUG
log4j.appender.Zmq.endpoint=tcp://127.0.0.1:5556
log4j.appender.Zmq.blocking=true
log4j.appender.Zmq.threads=1
log4j.appender.Zmq.socketType=pub
#log4j.appender.Zmq.socketType=push
#log4j.appender.Zmq.identity=localhost
log4j.appender.Zmq.topic=footopic
log4jExample.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package foo;
 
import org.apache.log4j.Logger;
 
import java.io.*;
import java.sql.SQLException;
import java.util.*;
 
public class Log4jExample {
/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(
Log4jExample.class.getName());
 
public static void main(String[] args)
throws IOException,SQLException{
log.debug("Hello this is an debug message");
log.info("Hello this is an info message");
}
}
send.sh
Shell
1
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/log4j.properties -Djava.library.path=/usr/local/lib foo.Log4jExample

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.