t0xa / gelfj

Graylog Extended Log Format (GELF) implementation in Java and log4j appender without any dependencies.
https://github.com/t0xa/gelfj/wiki
Other
187 stars 115 forks source link

noob question #83

Open skazal opened 10 years ago

skazal commented 10 years ago

In the documentation for "How to use GELFJ" it says:

"Grab latest JAR from the downloads section and drop it into your classpath. You will also need com.googlecode.json-simple, json-simple and log4j."

Forgive my ignorance, but what is the difference between "com.googlecode.json-simple" and "json-simple"? When I search for "com.googlecode.json-simple" they look like they're the same thing. If they're different, where do I find them?

Thanks!

t0xa commented 10 years ago

Hi,

I should keep mah wiki pages up to date. I recommend using Maven or Gradle to automatically manage your dependencies.

Add the following dependency section to your pom.xml:

<dependencies>
  ...
  <dependency>
    <groupId>org.graylog2</groupId>
    <artifactId>gelfj</artifactId>
    <version>1.1.7</version>
    <scope>compile</scope>
  </dependency>
  ...
</dependencies>

If you really need to download JAR you can do that via Maven Central.

If you need more help, let me know.

Thanks

skazal commented 10 years ago

Thanks, your instructions are appreciated, unfortunately I've never used maven or gradle and I have no idea what a pom.xml is. I'm trying to use customize a vendor's product to use GELFJ to leverage the way they currently use log4j to write local log files and get their software to also send the log data to a Graylog2 server. I'm smart on some things but fairly clueless with what I need to do here.

t0xa commented 10 years ago

Fair enough.

  1. Download gelfj JAR from http://search.maven.org/remotecontent?filepath=org/graylog2/gelfj/1.1.7/gelfj-1.1.7.jar
  2. Download JSON-Simple from http://search.maven.org/remotecontent?filepath=com/googlecode/json-simple/json-simple/1.1/json-simple-1.1.jar
  3. Check you log4j version as it may not be compatible
  4. Place jar from step 1 and 2 into classpath and add gelfj appender

Managing dependencies manually is like chasing your own tail. It may not be applicable for your legacy project but it's definitely worth investing your time into learning about Maven and/or Gradle.

skazal commented 10 years ago

Thanks, you have made me smarter. How do you identify the version of log4j? I will take your advice and learn more about Maven and Gradle. The project that I'm working on and if it works, will be very significant to the vendor and (more importantly) the administrators of the tools. One question I have is the vendor has a bunch of log4j '.properties' files for various components of their system. Will I have to modify each appender definition in each file to use gelfj or is there a way to globally define it in one place so all existing loggers and any new ones will automatically send their messages to Graylog2?

t0xa commented 10 years ago

How do you identify the version of log4j?

You can look at the filename or you can just try and plug appender in and see if it works.

Will I have to modify each appender definition in each file to use gelfj or is there a way to globally define it in one place so all existing loggers and any new ones will automatically send their messages to Graylog2?

It depends on the content of the properties files. Maybe it was intentional to have many and they serve different purpose. I recommend reviewing these files first and adjusting one by one.

skazal commented 10 years ago

Thanks. One last question for today. In the application logs, shortly after starting the application I'm seeing the message : log4j:ERROR Could not send GELF message. Where should I look for more details. This is running on Win2008R2 server. The Graylog2 server is RHEL 6.2 The application is using log4j -1.2.14

t0xa commented 10 years ago

Hi, sorry I somehow missed your questions. Is this still actual?

VeryVery commented 10 years ago

I don't know how to send the message to the graylog2 after configuration the log4j, Is there a example java code? THX.

t0xa commented 10 years ago

Hi, You just need to use standard log4j functionality and log something.

Logger barlogger = Logger.getLogger("com.foo.Bar");
barlogger.info("Located nearest gas station.");

Please look at Log4J tutorials.