Moocar / logback-gelf

Logback plugin to send GELF messages to graylog2 server
Apache License 2.0
147 stars 59 forks source link

How to install for a Java newbie #56

Closed gtaylor closed 9 years ago

gtaylor commented 9 years ago

Hello!

I'm running DataStax Enterprise 4.7, which is a packaged commercial version of Cassandra. As of 4.7, it looks like the whole thing switched from log4j to logback. If I wanted to use this GELF appender, how would I go about dropping this in?

I was assuming I'd need to compile this somehow and drop it into a my classpath, but wasn't sure how to get started on the former (my background is primarily Python-oriented). Do you have any suggestions as far as how to proceed? It seems like this is exactly what I'm looking for, so I'd love to use it.

Moocar commented 9 years ago

Hey there,

Interesting use case. Most users of this library use it in their own applications by just depending on it in their maven pom.xml. In this case, you'll probably have to drop in the logback-gelf jar and its dependencies directly. I see two possibilities. Each has their own advantage/disadvantage.

1. Include jar + dependencies

This option guarantees that you're not accidentally overriding Cassandra's built in dependency versions. However you need to manually include the dependency jars, if the logback-gelf dependencies ever change, you'll also need to update them,

logback-gelf requires the following dependencies:

  1. org.slf4j/slf4j-api
  2. ch.qos.logback/logback-classic
  3. com.google.code.gson/gson
  4. me.moocar/socket-encoder-appender

Now that Cassandra uses Logback, 1 & 2 will be included in the Cassandra uberjar. So you don't need to include those. You'll need to include gson, but luckily it has no dependencies of its own. If you want to use the TCP appender, you'll need to include socket-encoder-appender, but thankfully its only 2 dependencies are 1 & 2 so there are no extra dependencies to pull in as a result.

To actually download the jars, I use maven central. E.g you can download the gson jar from here: http://search.maven.org/#artifactdetails%7Ccom.google.code.gson%7Cgson%7C2.3.1%7Cjar.

Once downloaded, add the jars to the classpath using java -cp cassandra.jar;gson.jar;logback-gelf.jar ....

2. Build and include uberjar

This option guarantees that all logback-gelf dependencies are added to the classpath, but you may inadvertently override versions that Cassandra relies on. But, it means you won't have to manually keep up to date with logback's dependencies.

To do this, you'd simply run mvn package and then include the resulting target/logback-gelf-0.2beta4-SNAPSHOT.jar on the Cassandra classpath.

gtaylor commented 9 years ago

This is amazing, Anthony. I appear to have done #2 (without success), and will try #1 tomorrow. If I can figure this out, expect a blog post and/or doc pull request!

gtaylor commented 9 years ago

My issue ended up being that I was missing gson.

With the help of DataStax support, here's what we did:

Did what you said and dropped gson in. Problem solved, logs sending.

Your help is much appreciated. I'll follow up with a blog post on this shortly, and if there's somewhere in this repo (or Wiki) that you'd like a writeup, I'd be glad to take everything here and package it up.

Moocar commented 9 years ago

Awesome! That's great to hear. If you create a write up, let me know and I'll either link to it from the main README or we can chuck it in the wiki. I'm sure it will be useful for someone in the future.

jlengrand commented 9 years ago

Really cool. This helped me a lot. For some reason we're still stuck in the last century and not using maven yet :).