Enterprise grade Java.
You'll read about Conferences, Java User Groups, Java, Integration, Reactive, Microservices and other technologies.

Friday, October 30, 2009

Log4J Twitter Appender - twitter your logmessages :)

09:22 Friday, October 30, 2009 Posted by Markus Eisele
, , ,
Don't ask me why, but I was thinking about a "twittering" WebLogic for some days now. And I finaly managed to spend some minutes on this today. This is the first approach. Have some more in mind and would like to contribute them, too.

Let's start over with the Log4JTwitterAppender:
You can download the jar directly. Anything else you need is a recent version of Log4J and JTwitter. I used Log4J 1.2.15 and JTwitter 1.2. Now drop all three jars log4j-1.2.15.jar, jtwitter.jar and l4jtwitterappender.jar to your project and add a log4j.properties file to it.

A sample log4j.properties looks like this:

# Add the twitter appender
log4j.rootLogger=DEBUG, TWITTER
[%d{MMM dd HH:mm:ss}] %-5p (%.20F) - %.49m%n

If everything is configured, you can start logging:

private static final Logger log =

log.debug("your log message");

If everything works fine, you now have a logging twitter account :)

You can configure the layout if you like with the normal PatternLayout machanism. But to be honest ... 140 characters are hardly enough for log messages :)
Anyway, it was fun doing it ...