You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Logging

Apache Tika include a lot of Apache and thirdparty libraries that have different approach to logging.

tika-core

tika-core should have no external dependencies to be as lightweight as it can, so we have to use
java.util.logging there.

tika-parsers

tika-parsers depends on many Apache and thirdparty libraries. Currently, parsers in it usually use logging approach from underlying library, e. g. parsers in o.a.tika.parsers.microsoft which use Apache POI depends on Apache Commons Logging and Apache Log4j 1.2.

Currently tika-parsers depends on these logging solutions:

It makes logging in application (which depends on tika-parsers) a bit harder.

One way to have consistent logging (i. e. one logging configuration point) is to choose one backend and use slf4j as integration api.

In this case exclude all other logger deps except choosen logging backend and add all appropriate bridges.

If you use Apache Maven dependency section in pom.xml will contain something like this:

{{{#!xml
<properties>
<tika.version>1.14</tika.version>
<slf4j.version>1.7.22</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>${tika.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
}}}

If you want to use native slf4j implementation, you can use logback:

{{{#!xml
<properties>
<tika.version>1.14</tika.version>
<slf4j.version>1.7.22</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>${tika.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
</dependency>
</dependencies>
}}}

  • No labels