This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree
Skip to end of metadata
Go to start of metadata

Current state

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

tika-core

tika-core 1.x should have no external dependencies to be as lightweight as it can, so we have to use
java.util.logging there whereas tika-core 2.x will use slf4j-api.

tika-parsers

tika-parsers depends on many Apache and thirdparty libraries. Currently, parsers in it use either slf4j-api or 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.

Goal is to use slf4j-api for logging in all parsers with included dependencies on org.slf4j:jul-to-slf4j and org.slf4j:jcl-over-slf4j to allow user simply add and configure log4j:log4j (Apache Log4j 1.2.x) in simple case. If downstream user wish to use different logging backend for slf4j he/she will have to include org.slf4j:log4j-over-slf4j, include backend implementation and exclude conflicting bridges (in case of using jcl/commons-logging or java.util.logging as backends). Following sections shows how to configure different logging solutions/backends dependencies to avoid conflicts. Loggers configuration are out of scope of this document, you should look at relevant library documentation.

Currently tika-parsers depends on these logging solutions:

Example configuration for Apache Tika 1.x

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

Common sections

<!-- Merge with your properties section -->
<properties>
<!-- components versions, feel free keep only required for your case -->
<tika.version>1.20</tika.version>
<slf4j.version>1.7.26</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.11.2</log4j2.version>
<logback.version>1.2.3</logback.version>
</properties>

<!-- Merge with your dependencies section -->
<dependencies>
<dependency> <groupId>org.apache.tika</groupId> <artifactId>tika-parsers</artifactId> <version>${tika.version}</version> <exclusions>
<!--
This exclusion will become obsolete at some point but better to keep it now.
tika-parsers usually excludes commons-logging explicitly but upstream libraries
may add it to their direct or transitive dependencies
--> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency>

<!--
You may want to add these dependencies to dependencyManagement to force consistent version if you wish.
tika-parsers have slf4j-api, jul-to-slf4j and jcl-over-slf4j as dependencies explicitly,
so they are here primary as example.
-->
<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> </dependencies>

Apache Log4j 1.2.x

<!-- Merge with your dependencies section -->
<dependencies> <!-- slf4j implementation to forward logs to log4j 1.2.x --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency>

<!-- logging backend: log4j 1.2.x -->
<!-- this dependency declaration is optional since org.slf4j:slf4j-log4j12 depends on it transitively -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency> </dependencies>

Logback

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

<!-- Merge with your dependencies section -->
<dependencies>
<!-- bridges to route jul and jcl (commons-logging) are already present, so just add log4j 1.2.x one -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- slf4j implementation -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>

Apache Log4j 2.x with slf4j bridges

<dependencies>
<!-- bridges to route jul and jcl (commons-logging) are already present, so just add log4j 1.2.x one -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- slf4j implementation to forward logs to log4j 2.x -->
 <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

<!-- logging backend: log4j 2.x -->
  <!-- this dependency declarations are optional since org.apache.logging.log4j:log4j-slf4j-impl depends on them transitively -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version></version>
</dependency>
 <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version></version>
</dependency>
</dependencies>

Apache Log4j 2.x with native bridges

<dependencies>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>${tika.version}</version>
<exclusions>
<!--
This exclusion will become obsolete at some point but better to keep it now.
tika-parsers usually excludes commons-logging explicitly but upstream libraries
may add it to their direct or transitive dependencies
-->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<!-- We exclude slf4j bridges and replace them with native log4j 2.x ones below -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
 <exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- slf4j implementation to forward logs to log4j 2.x -->
  <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

<!-- log4j 2.x bridges to forward java.util.logging, jcl/commons-logging and log4j 1.2.x to log4j 2.x -->
  <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>${log4j2.version}</version>
</dependency>
  <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>

<!-- logging backend: log4j 2.x -->
  <!-- this dependency declarations are optional since org.apache.logging.log4j:log4j-slf4j-impl depends on them transitively -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version></version>
</dependency>
  <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version></version>
</dependency>
</dependencies>

_


  • No labels