简体   繁体   English

HttpClient,Log4J和Maven jar冲突

[英]HttpClient, Log4J and Maven jar conflicts

I have a Maven POM file using org.apache.httpcomponents wich includes commons-logging (I don't need to include this dependency) 我有一个使用org.apache.httpcomponents的Maven POM文件,其中包括commons-logging(我不需要包括此依赖项)

But I need to use Log4J, and it's causing conflicts by including commons-logging JAR and Log4J JARS in same project. 但是我需要使用Log4J,并且通过在同一项目中包含记录日志的JAR和Log4J JARS引起冲突。

This conflict causing duplicating lines in my log file. 此冲突导致我的日志文件中的行重复。

My POM (extract): 我的POM(摘录):

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.0-beta5</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.0-beta5</version>
</dependency>

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.0.1</version>
</dependency>

<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.6</version>
</dependency>       

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient-cache</artifactId>
    <version>4.2.3</version>
</dependency>       

I try to put an exclusion tag in org.apache.httpcomponents for commons-loggin, but I got a Runtime error in HttpClient class (no compile error). 我尝试在org.apache.httpcomponents中为commons-loggin放置一个排除标记,但是HttpClient类中出现运行时错误(无编译错误)。

What can I do? 我能做什么?

Well, my fault! 好吧,我的错!

Seems the specific class logger is stacked with root logger. 似乎特定的类记录器与根记录器堆叠在一起。

First log line is for specific class logger ( the logger called by class name ) and second line (duplicate) is for root logger. 第一行日志用于特定的类记录器(由类名调用的记录器),第二行(重复)用于根记录器。 This is my log4j XML config: 这是我的log4j XML配置:

<loggers>
    <Logger name="cmabreu.sagitarii.teapot.Main" level="debug"> 
        <appender-ref ref="File"/> 
    </Logger>

    <root level="error">
        <appender-ref ref="File" />
    </root>
</loggers>

I need to add additivity="false" for specific logger (cmabreu.sagitarii.teapot.Main), this way it will not stack with root logger. 我需要为特定的记录器(cmabreu.sagitarii.teapot.Main)添加additivity="false" ,这样它就不会与根记录器堆叠在一起。

<Logger name="cmabreu.sagitarii.teapot.Main" level="debug" additivity="false">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM