My favorites | Sign in
Project Logo
          
People details
Project owners:
  talsalmona

Log4J Twitter Appender

It is useful to log error messages to a mobile device so that errors in your production servers can be quickly resolved. Twitter is a great way to keep up to date with your other interests so why not your server logs?

In HiveSight we did just that. Here is an implementation of a Lo4J Appender that sends log messages to your Twitter.

Here is an example of how it is added as an appender using a ''log4j.properties'' file:

log4j.rootLogger=INFO, TWITTER

log4j.appender.TWITTER=com.hivesight.infra.log4j.TwitterAppender
log4j.appender.TWITTER.username=[your twitter username]
log4j.appender.TWITTER.password=[your twitter password]
log4j.appender.TWITTER.urlTemplate=http://twitter.com/statuses/update.xml
log4j.appender.TWITTER.layout=org.apache.log4j.PatternLayout
log4j.appender.TWITTER.layout.ConversionPattern=%d %-5p %c %x - %m%n
log4j.appender.TWITTER.Threshold=ERROR

Two things you should be aware of before using this:

  1. Be aware of the Twitter API Rate Limiting and other technical or legal limitations that are related to the way you intend to use this code.
  2. Twitter messages are limited to 140 characters, longer messages will be trimmed.
  3. This appender works by utilizing the commons-httpclient to send a POST request to the Twitter API so make sure you have commons-httpclient in your classpath

Source Code is available from Subversion. You can also view it here









Hosted by Google Code