Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Treasure Data Logging Library for Java

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 core [maven-release-plugin] prepare for next development iteration October 15, 2013
Octocat-spinner-32 gae
Octocat-spinner-32 .gitignore
Octocat-spinner-32 AUTHORS.txt
Octocat-spinner-32 CHANGES.txt changed CHANGES.txt June 30, 2013
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 pom.xml

Treasure Data Logger for Java


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.

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

td-logger-java is a Java library, to record events from Java application.


Java >= 1.6


Install with all-in-one jar file

You can download all-in-one jar file for Treasure Data Logger.

$ wget${logger.version}/td-logger-${logger.version}-jar-with-dependencies.jar

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

Install from Maven repository

Treasure Data Logger for Java is released on Treasure Data's Maven repository. You can configure your pom.xml as follows to use it:


    <name>Treasure Data's Maven Repository</name>
    <name>Fluentd's Maven Repository</name>

Install with SBT (Build tool Scala)

To install td-logger From SBT (a build tool for Scala), please add the following lines to your build.sbt.

/* in build.sbt */
// Repositories
resolvers ++= Seq(
  "td-logger     Maven Repository" at "",
  "fluent-logger Maven Repository" at ""
// Dependencies
libraryDependencies ++= Seq(
  "com.treasure_data" % "td-logger" % "${logger.version}"

Install from GitHub repository

You can get latest source code using git.

$ git clone
$ cd td-logger-java
$ mvn package

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

Replace ${logger.version} with the current version of Treasure Data Logger for Java. The current version is 0.1.3.


Small example with Treasure Data Logger

The following program is a small example of td-logger.

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.treasure_data.logger.TreasureDataLogger;

public class Main {
    private static TreasureDataLogger LOG;

    static {
        try {
            Properties props = System.getProperties();
            LOG = TreasureDataLogger.getLogger("my_database");
        } catch (IOException e) {
            // do something

    public void doApp() {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("from", "userA");
        data.put("to", "userB");
        LOG.log("my_follow_table", data);

See static initializer in Main class. To create TreasureDataLogger objects, you need to invoke getLogger method in TreasureDataLogger class like well-known logging libraries. The method should be called only once.

Close method in TreasureDataLogger class should be called explicitly when your application is finished (or undeployed). Once the method is executed, all TreasureDataLogger objects that you created are closed.


See doApp method in Main class. log method enables you to upload event logs. Event logs should be declared as variables of Map<String, Object> type. The key is String type. The type of value is one of the followings: int, long, string, float, double.

Direct upload and In-direct upload

You can choose how to upload event logs from the following methods. Installing td-agent is here.

  • Direct upload from your applications
  • In-direct upload from td-agent

To switch between them, you can specify Java options and system properties on the command line, or by using an options file. If you want to directly upload event logs from your application, you should set your own values to the following properties in file.

td.logger.api.key=<your API key>

On the other hand if you want to upload data via td-agent, you should declare the following properties in the file.

td.logger.agentmode=true<your td-agent host>
td.logger.agent.port=<your td-agent port>


Apache License, Version 2.0

Something went wrong with that request. Please try again.