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
OPENNLP-675Getting issue details...
. This proposal presents a method for allowing the user to customize the default logging behavior when OpenNLP is used as a library.
As discussed above, OpenNLP currently (as of 1.7.2) defaults to using
System.err() for logging messages and errors, respectively.
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).
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.)
The naming of objects in this proposal is mainly for illustrative purposes. I'm not proposing any specific naming and am open to naming suggestions.
An example of the logging interface is:
The default implementation used when the user has not provided an implementation of
Logger will be:
DefaultLogger class mimics the current behavior of OpenNLP of using
A new project contains the
Logger interface to avoid circular dependencies.
A new class in OpenNLP would be created that stores a static reference to the
Logger implementation. By default this static variable would reference the
DefaultLogger. The user can set their own
Logger implementation at any time through the
Existing logging statements in OpenNLP would be modified to perform the logging via the
LoggingConfiguration class. For example, from NameSampleCountersStream:
- Presents a way to let users of OpenNLP as a library to control logging.
- A new project that contains a Logger interface.
- Modifying current
System.err()calls to reference the new
A similar approach could be taken for functions that expect a