Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A structured logger for Fluentd (Java)
Java

Merge pull request #43 from HenryYao369/master

fixed the URL where all-in-one jar file is put in README.md.

Merge https://github.com/HenryYao369/fluent-logger-java

Conflicts:
	README.md
latest commit 2795fd57c2
@muga muga authored

README.md

Fluent Logger for Java

Overview

Many web/mobile applications generate huge amount of event logs (c,f. login, logout, purchase, follow, etc). Analyzing these event logs can be quite valuable for improving services. However, collecting these logs easily and reliably is a challenging task.

Fluentd solves the problem by having: easy installation, small footprint, plugins, reliable buffering, log forwarding, etc.

fluent-logger-java is a Java library, to record events via Fluentd, from Java application.

Requirements

Java >= 1.6

Install

Install with all-in-one jar file

You can download all-in-one jar file for Fluent Logger for Java.

$ wget http://central.maven.org/maven2/org/fluentd/fluent-logger/${logger.version}/fluent-logger-${logger.version}-jar-with-dependencies.jar   

To use Fluent Logger for Java, set the above jar file to your classpath.

Install from Maven2 repository

Fluent Logger for Java is released on Fluent Maven2 repository. You can configure your pom.xml as follows to use it:

<dependencies>
  ...
  <dependency>
    <groupId>org.fluentd</groupId>
    <artifactId>fluent-logger</artifactId>
    <version>${logger.version}</version>
  </dependency>
  ...
</dependencies>

Install from Github repository

You can get latest source code using git.

$ git clone git@github.com:fluent/fluent-logger-java.git
$ cd fluent-logger-java
$ mvn assembly:assembly

You will get the fluent logger jar file in fluent-logger-java/target directory. File name will be fluent-logger-${logger.version}-jar-with-dependencies.jar. For more detail, see pom.xml.

Replace ${logger.version} with the current version of Fluent Logger for Java.

Quickstart

The following program is a small example of Fluent Logger for Java.

import java.util.HashMap;
import java.util.Map;
import org.fluentd.logger.FluentLogger;

public class Main {
    private static FluentLogger LOG = FluentLogger.getLogger("app");

    public void doApplicationLogic() {
        // ...
        Map<String, String> data = new HashMap<String, String>();
        data.put("from", "userA");
        data.put("to", "userB");
        LOG.log("follow", data);
        // ...
    }
}

To create Fluent Logger instances, users need to invoke getLogger method in FluentLogger class like org.slf4j, org.log4j logging libraries. The method should be called only once. By default, the logger assumes fluent daemon is launched locally. You can also specify remote logger by passing the following options.

// for remote fluentd
private static FluentLogger LOG = FluentLogger.getLogger("app", "remotehost", port);

Then, please create the events like this. This will send the event to fluentd, with tag 'app.follow' and the attributes 'from' and 'to'.

Close method in FluentLogger class should be called explicitly when application is finished. The method closes socket connection with the fluentd.

FluentLogger.close();

License

Apache License, Version 2.0

Something went wrong with that request. Please try again.