Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Document statusDRAFT
Document owner

Jeff Zemerick

Introduction

OpenNLP uses System.out() and System.err() by default for logging. This is fine for instances in which OpenNLP's CLI tools are being used but may not be ideal when OpenNLP is used as a library. Previous work in this area includes 

Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyOPENNLP-675
. This proposal presents a method for allowing the user to customize the default logging behavior when OpenNLP is used as a library.

Current State

As discussed above, OpenNLP currently (as of 1.7.2) defaults to using System.out() and System.err() for logging messages and errors, respectively.

The Problem

When using OpenNLP as a library the output of logs to standard out and standard error is not ideal as these logs often need to be captured by the application for external storage and reporting (and also just to keep from cluttering up standard out).

Proposed Solution

The proposed solution is to create an OpenNLP Logger interface that developers can implement to customize the logging. The user can provide their own implementation of this interface to control OpenNLP's logging. This interface will have to exist in a new project (perhaps opennlp-model?) in order to avoid circular dependencies. (The opennlp-tools project will have a dependency on this project. The user's project can either have an explicit dependency on opennlp-model or a transitive dependency based on the project's requirements.)

...

CurrentProposed
Code Block
  public void printSummary() {

    System.out.println("Training data summary:");

    System.out.println("#Sentences: " + getSentenceCount());

    System.out.println("#Tokens: " + getTokenCount());




    int totalNames = 0;

    for (Map.Entry<String, Integer> counter : getNameCounters().entrySet()) {

      LoggerConfiguration.getLogger().log("#" + counter.getKey() + " entities: " + counter.getValue());

      totalNames += counter.getValue();

    }

  }
Code Block
  public void printSummary() {

    LoggerConfiguration.getLogger().log("Training data summary:");

    LoggerConfiguration.getLogger().log("#Sentences: " + getSentenceCount());

    LoggerConfiguration.getLogger().log("#Tokens: " + getTokenCount());




    int totalNames = 0;

    for (Map.Entry<String, Integer> counter : getNameCounters().entrySet()) {

      LoggerConfiguration.getLogger().log("#" + counter.getKey() + " entities: " + counter.getValue());

      totalNames += counter.getValue();

    }

  }

Summary

This proposal:

  • Presents a way to let users of OpenNLP as a library to control logging.
  • Requires:
    • A new project that contains a Logger interface.
    • Modifying current System.out() and System.err() calls to reference the new LoggerConfiguration class.

Future Work

A similar approach could be taken for functions that expect a PrintStream object.

...