GVKun编程网logo

启用Log4J2 + Apache HttpClient的debugging日志logging(log4jconfiglistener)

168

想了解启用Log4J2+ApacheHttpClient的debugging日志logging的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于log4jconfiglistener的相关问题

想了解启用Log4J2 + Apache HttpClient的debugging日志logging的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于log4jconfiglistener的相关问题,此外,我们还将为您介绍关于004-log-common-logging,Apache整合日志框架JCL门面框架、JCL+log4j、11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using ''c...、Apache httpd请求/响应日志logging、java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger的新知识。

本文目录一览:

启用Log4J2 + Apache HttpClient的debugging日志logging(log4jconfiglistener)

启用Log4J2 + Apache HttpClient的debugging日志logging(log4jconfiglistener)

即时尝试激活我的Apache HttpClient的debugging日志logging,但无法使其工作(得到没有任何logging输出是HttpClient相关)。

这是我现在使用的log4j2configuration:

<?xml version="1.0" encoding="UTF-8"?> <configuration status="OFF"> <appenders> <Console name="console" target="SYstem_OUT"> <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingRandomAccessFile" fileName="logs/test.log" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz"> <PatternLayout> <Pattern> %d %p %c{1.} [%t] %m%n </Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="10 MB" /> </Policies> <DefaultRolloverStrategy max="20" /> </RollingFile> <Async name="async"> <AppenderRef ref="RollingRandomAccessFile" /> </Async> </appenders> <loggers> <logger name="org.apache.http.wire" level="debug" /> <logger name="org.apache.http.client" level="debug" /> <logger name="org.apache.xerces.parsers.SAXParser" level="warn" /> <logger name="org.hibernate" level="warn" /> <root level="trace"> <appender-ref ref="console" /> <appender-ref ref="async" /> </root> </loggers> </configuration>

例如,将警告的级别从“警告”更改为“debugging”可以完美实现。

这些库即时使用:

MobaXterm:将所有NEWterminal活动logging在单独的文件中?

批量redirect输出标准错误到文件和pipe道输出标准输出到文件

如何编写写入/ var / log / myapp目录的C / C ++应用程序?

使用C&Windows从混音器录制声音

用于实时和非实时应用程序的日志logging工具

<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>fluent-hc</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.2.5</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-cache</artifactId> <version>4.2.6</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.2.6</version> </dependency>

Log4J2

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

有人有想法吗? 我尝试了不同的软件包名称

httpclient.wire httpclient.wire.header httpclient.wire.content

还有一些,但似乎没有工作…

您使用Windows的哪些logging工具?

如何在shell脚本中复制新的日志文件的新条目或新行?

在Nginx中logging代理活动

实时logging

快速远程logging系统?

我假设httpcomponents在内部使用log4j-1.2。 Log4j2提供了一个适配器,可以将使用1.2 API的应用程序的调用路由到新的2.0实现。

要启用这个功能,只需要将log4j-core和log4j-1.2-api jar添加到你的类路径中即可。 (你目前的Maven依赖只有log4j-api,这是新的2.0 API。)另见http://logging.apache.org/log4j/2.x/faq.html 。

Remko是正确的,问题是内部使用log4j-1.2的httpcomponents。 将log4j 1.2路由到log4j 2的适配器称为log4j 1.2网桥,在这里描述: https : //logging.apache.org/log4j/2.x/log4j-1.2-api/index.html 。

log4j的maven工件页面正确地解释了如何配置你的maven依赖包含桥接库:

Log4j 1.x API桥

如果现有组件使用Log4j 1.x并且您希望将此日志记录路由到Log4j 2,请删除所有log4j 1.x依赖项并添加以下内容。

<dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-1.2-api</artifactId> <version>2.5</version> </dependency> </dependencies>

从https://logging.apache.org/log4j/2.x/maven-artifacts.html

004-log-common-logging,Apache整合日志框架JCL门面框架、JCL+log4j

004-log-common-logging,Apache整合日志框架JCL门面框架、JCL+log4j

一、概述

  Jakarta Commons Logging (JCL)提供的是一个日志(Log)接口(interface),同时兼顾轻量级和不依赖于具体的日志实现工具。它提供给中间件/日志工具开发者一个简单的日志操作抽象,允许程序开发人员使用不同的具体日志实现工具。用户被假定已熟悉某种日志实现工具的更高级别的细节。JCL提供的接口,对其它一些日志工具,包括Log4J, Avalon LogKit, and JDK 1.4等,进行了简单的包装,此接口更接近于Log4J和LogKit的实现。

  在Logging系统中,目前框架都是基于相同的设计,即从一个LogFactory中取得一个命名的Log(Logger)实例,然后使用这个Log(Logger)实例打印debug、info、warn、error等不同级别的日志。作为两个门面日志系统,Commons Logging和SLF4J也同样采用这样的设计。 
所谓门面日志系统,是指它们本身并不实现具体的日志打印逻辑,它们只是作为一个代理系统,接收应用程序的日志打印请求,然后根据当前环境和配置,选取一个具体的日志实现系统,将真正的打印逻辑交给具体的日志实现系统,从而实现应用程序日志系统的“可插拔”,即可以通过配置或更换jar包来方便的更换底层日志实现系统,而不需要改变任何代码。个人感觉SLF4J的实现更加灵活,并且它还提供了Maker和MDC的接口。

1.1、pom依赖

<dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

1.2、配置

  创建commons-logging.properties文件,将其放在classpath下,如果是maven项目则将其放在src/main/resource目录下,配置内容如下

org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

1.3、使用

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ApplicationMain {
    private static Log logger = LogFactory.getLog(ApplicationMain.class);

    public static void main(String[] args) {
        System.out.println(logger.getClass().getName());
        // 记录debug级别的信息
        logger.debug("This is debug message.");
        // 记录info级别的信息
        logger.info("This is info message.");
        // 记录error级别的信息
        logger.error("This is error message.");
    }
}

二、详细说明

    

2.1、LogFactory获取相对应的Log实现类逻辑

JCL有两个基本的抽象类:Log(基本记录器)和LogFactory(负责创建Log实例)。当commons-logging.jar被加入到 CLASSPATH之后,它会合理地猜测你想用的日志工具,然后进行自我设置,用户根本不需要做任何设置。默认的LogFactory是按照下列的步骤去发现并决定那个日志工具将被使用的(按照顺序,寻找过程会在找到第一个工具时中止): 
  1. 寻找当前factory中名叫org.apache.commons.logging.Log配置属性的值 
  2. 寻找系统中属性中名叫org.apache.commons.logging.Log的值 
  3. 如果应用程序的classpath中有log4j,则使用相关的包装(wrapper)类(Log4JLogger) 
  4. 如果存在Lumberjack版本的Logging系统,则使用Jdk13LumberjackLogger类。 
  5. 如果应用程序运行在jdk1.4的系统中,使用相关的包装类(Jdk14Logger) 
  6. 使用简易日志包装类(SimpleLog) 
  7. 以上步骤都失败,则抛出LogConfigurationException。

LogFactory使用动态查找机制进行日志实例化,执行顺序为:common-logging.properties---->系统环境变量------->log4j--->jul--->simplelog---->nooplog

org.apache.commons.logging.Log的具体实现:

  org.apache.commons.logging.Log的具体实现有如下: 
  - org.apache.commons.logging.impl.Jdk14Logger 使用JDK1.4。 
  - org.apache.commons.logging.impl.Log4JLogger 使用Log4J。 
  - org.apache.commons.logging.impl.LogKitLogger 使用 avalon-Logkit。 
  - org.apache.commons.logging.impl.SimpleLog common-logging自带日志实现类。它实现了Log接口,把日志消息都输出到系统错误流System.err 中。 
  - org.apache.commons.logging.impl.NoOpLog common-logging自带日志实现类。它实现了Log接口。 其输出日志的方法中不进行任何操作。

2.2、日志级别

1)fatal 非常严重的错误,导致系统中止。期望这类信息能立即显示在状态控制台上。

2)error 其它运行期错误或不是预期的条件。期望这类信息能立即显示在状态控制台上。

3)warn 使用了不赞成使用的API、非常拙劣使用API, ''几乎就是''错误, 其它运行时不合需要和不合预期的状态但还没必要称为 "错误"。期望这类信息能立即显示在状态控制台上。

4)info 运行时产生的有意义的事件。期望这类信息能立即显示在状态控制台上。

5)debug 系统流程中的细节信息。期望这类信息仅被写入log文件中。

6)trace 更加细节的信息。期望这类信息仅被写入log文件中。

如上述配置了SimpleLog,增加simplelog.properties配置文件,放到classpath下,如果是maven则放到src/main/resource目录下,配置内容参考:
org.apache.commons.logging.simplelog.defaultlog=TRACE

2.3、LogFactory实现原理

  LogFactory作为log的工厂存在,使用动态查找机制进行log实例的获取,具体执行步骤如下:

  ①首先在classpath下寻找commons-logging.properties文件。如果找到,则使用其中定义的Log实现类;如果找不到,则在查找是否已定义系统环境变量org.apache.commons.logging.Log,找到则使用其定义的Log实现类;

  ②查看classpath中是否有Log4j的包,如果发现,则自动使用Log4j作为日志实现类;

  ③使用JDK自身的日志实现类(JDK1.4以后才有日志实现类);

  ④使用commons-logging自己提供的一个简单的日志实现类SimpleLog;

  上述步骤当LogFactory成功找到一个日志实现之后就会停止

  LogFactory的核心步骤在于discoverLogImplementation方法,源码分析如下:

if (isDiagnosticsEnabled()) {
            this.logDiagnostic("Discovering a Log implementation...");
        }

        this.initConfiguration();
        Log result = null;
        //从common-logging.properties文件中提取org.apache.commons.logging.Log这个变量的value
        String specifiedLogClassName = this.findUserSpecifiedLogClassName();

        //配置文件中存在该变量则实例化
        if (specifiedLogClassName != null) {
            if (isDiagnosticsEnabled()) {
                this.logDiagnostic("Attempting to load user-specified log class ''" + specifiedLogClassName + "''...");
            }

            //核验相应日志对象是否存在
            result = this.createLogFromClass(specifiedLogClassName, logCategory, true);

            //如果日志对象不存在,则报错
            if (result == null) {
                StringBuffer messageBuffer = new StringBuffer("User-specified log class ''");
                messageBuffer.append(specifiedLogClassName);
                messageBuffer.append("'' cannot be found or is not useable.");
                this.informUponSimilarName(messageBuffer, specifiedLogClassName, "org.apache.commons.logging.impl.Log4JLogger");
                this.informUponSimilarName(messageBuffer, specifiedLogClassName, "org.apache.commons.logging.impl.Jdk14Logger");
                this.informUponSimilarName(messageBuffer, specifiedLogClassName, "org.apache.commons.logging.impl.Jdk13LumberjackLogger");
                this.informUponSimilarName(messageBuffer, specifiedLogClassName, "org.apache.commons.logging.impl.SimpleLog");
                throw new LogConfigurationException(messageBuffer.toString());
            } else {
                return result;
            }
        } else {
            //当日志文件中不存在该变量时,按照机制遍历classesToDiscover字符串数组

            if (isDiagnosticsEnabled()) {
                this.logDiagnostic("No user-specified Log implementation; performing discovery using the standard supported logging implementations...");
            }

            //遍历classesToDiscover字符串数组获取日志实例(动态查找机制)
            for(int i = 0; i < classesToDiscover.length && result == null; ++i) {
                result = this.createLogFromClass(classesToDiscover[i], logCategory, true);
            }

            //到最后仍旧找不到匹配的日志实例,则抛错
            if (result == null) {
                throw new LogConfigurationException("No suitable Log implementation");
            } else {
                return result;
            }
        }

三、common-logging+log4j应用

3.1、POM依赖

<dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

3.2、配置文件

  在commons-logging.properties文件,将log指向log4j,可以不加因为默认的,没有的话会先加载log4j

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

  配置log4j.properties配置【可以参看002-log-log4j】

### 设置###
log4j.rootLogger = debug,stdout,D,E

### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

### 输出DEBUG 级别以上的日志到 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

### 输出ERROR 级别以上的日志到error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
View Code

3.2、java代码依旧使用logging代码即可

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ApplicationMain {
    private static Log logger = LogFactory.getLog(ApplicationMain.class);

    public static void main(String[] args) {
        System.out.println(logger.getClass().getName());
        // 记录debug级别的信息
        logger.debug("This is debug message.");
        // 记录info级别的信息
        logger.info("This is info message.");
        // 记录error级别的信息
        logger.error("This is error message.");
    }
}

输出

org.apache.commons.logging.impl.Log4JLogger
[DEBUG] 2019-06-21 14:07:37,823 method:com.github.bjlhx15.common.study.log.ApplicationMain.main(ApplicationMain.java:13)
This is debug message.
[INFO ] 2019-06-21 14:07:37,826 method:com.github.bjlhx15.common.study.log.ApplicationMain.main(ApplicationMain.java:15)
This is info message.
[ERROR] 2019-06-21 14:07:37,826 method:com.github.bjlhx15.common.study.log.ApplicationMain.main(ApplicationMain.java:17)
This is error message.

 

  

 

11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using ''c...

11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using ''c...

11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using ''class org.apache.ibatis.logging.slf4j.Slf4jImpl'' adapter.

org.apache.ibatis.exceptions.PersistenceException: 
### Error opening session.  Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100)
	at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
	at com.website.DB.DBAcess.getSqlSession(DBAcess.java:15)
	at com.website.controller.ProductControllerTest.insert(ProductControllerTest.java:58)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.NullPointerException
	at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:95)
	... 25 more


Process finished with exit code -1

我使用Mybatis的时候,遇到了这个报错,不明所以,后来发现是因为我没有写数据库配置的原因

<!-- 设置一个默认的连接环境信息 -->
    <environments default="mysql_developer">
        <environment id="mysql_developer">
            <!-- mybatis使用jdbc事务管理方式 -->
            <transactionManager type="JDBC"></transactionManager>
            <!-- mybatis使用连接池方式来获取连接 -->
            <dataSource type="POOLED">
                <!-- 配置与数据库交互的4个必要属性,不要直接写,单独写在一个配置文件中 -->
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://127.0.0.1:3306/shuyunquan?serverTimezone=UTC"/>
                <property name="username" value="root"/>
                <property name="password" value="123"/>
            </dataSource>
        </environment>
    </environments>

就是这个,我没配置,我在application.yml里面已经配置了数据库连接了,所以这里没有配置,同时也忘了使用properties标签去引入数据库配置。所以才导致了这个错误。

Apache httpd请求/响应日志logging

Apache httpd请求/响应日志logging

有没有办法用Apachelogging请求(完整的GET URI,响应和POST数据和响应)的内容? 我有一堆通过HTTP与客户端进行通信的游戏,他们使用不同的variables并输出各种各样的东西。

我想推进所有这些内容到数据库进一步处理,所以我可以一步一步地报告游戏。 无法修改服务器端游戏文件来logging这些数据,它们太多(数千)。

这不是太多的数据,高达512字节或每个请求和响应数据1K。

不能设置一个清漆或鱿鱼来做到这一点,我有很多的后端服务器,不能再添加一层到这个,我有负载的东西之前发生的应用服务器(负载平衡,防火墙,whatnot )。

Apache Solrsearch自动完成

PHP空$ _POST

debugging和testingmod_rewrite(.htaccess)指令的工具

在Sierra OSX更新之后,MAMP不工作

在LAMPconfiguration中创build虚荣URL

TIA

的.htaccess。 拒绝根目录,允许特定的子文件夹。 可能?

如何用Apache做客户端证书authentication

如何在单个IP(Apache + Passenger)上部署多个rails应用程序?

notfound.html找不到

无法删除embedded式数据库的Derby系统目录

mod_dumpio会把它变成一个文件。

http://httpd.apache.org/docs/2.2/mod/mod_dumpio.html

java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger

java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger

如何解决java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger?

要解决您的问题,请添加以下缺少的依赖项:

  • org.apache.logging.log4j:log4j-api:2.8.2

另外,与问题没有直接关系,请添加以下依赖项,以便您自己对slf4j api的调用也将定向到log4j2实现:

  • org.apache.logging.log4j:log4j-slf4j-impl:2.8.2

确保在类路径上没有其他日志实现。

注意:我提出的“额外”建议是基于您想将所有日志调用重定向到log4j的,无论您是调用slf4j api还是直接调用log4j。如果不是,请说明您要使用哪种日志实现,因为那样的话,OP列出的依赖关系也会丢失。

解决方法

我想在我正在使用的Elasticsearch中执行单元测试,Java-test-framework
我正在使用Elasticsearch-1.6.0 并参考以下链接以寻求帮助
https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-
elasticsearch-test-classes .html

https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java

这是代码

class CampaignESTest extends ESTestCase {

  def getCLient():MockTransportClient={
     val settings = Settings.builder()
                .put(Environment.PATH_HOME_SETTING.getKey(),Files.createTempDir().toString())
                .build();
     val client = new MockTransportClient(settings);  
     client
  }
 }

class CampaignTestSearch extends PlaySpec{
  val client=new CampaignESTest

val response = client.prepareSearch("dbtest")
      .setTypes(CAMPAIGN_COLLECTION_NAME)
      .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
      .addFields("uuid","campaignName","artworkID","activationDate","_source")
      .setQuery(query)
      .execute()
      .actionGet()
  }

我收到这个例外

  DeferredAbortedSuite:
[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
[info]   at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
[info]   at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:92)
[info]   at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:78)
[info]   at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info]   at testcontrollers.campaign.CampaignTestSerach.<init>(CampaignTestSerach.scala:40)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[info]   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[info]   at java.lang.Class.newInstance(Class.java:442)
[info]   ...
[info]   Cause: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
[info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info]   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info]   at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101)
[info]   at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:92)
[info]   at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:78)
[info]   at org.elasticsearch.test.ESTestCase.<clinit>(ESTestCase.java:138)
[info]   at testcontrollers.campaign.CampaignTestSerach.<init>(CampaignTestSerach.scala:40)
[info]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info]   ...
[error] Uncaught exception when running testcontrollers.campaign.CampaignTestSerach: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger

在这条线上得到一个例外

val client=new CampaignESTest

在班上 CampaignTestSearch

这是build.sbt文件中的依赖项

   "org.slf4j" % "slf4j-api" % "1.6.4","org.elasticsearch" % "elasticsearch" % "1.6.0","org.elasticsearch.test" % "framework" % "5.0.0" % "test","org.apache.lucene" % "lucene-test-framework" % "4.10.4" % "test","com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "1.6.0" % "test","org.apache.lucene" % "lucene-codecs" % "4.10.4" % "test","org.apache.logging.log4j" % "log4j-core" % "2.8.2","org.apache.lucene" % "lucene-expressions" % "4.10.4",

我怀疑引起异常的原因可能是由于某些版本的依赖关系,任何人都可以帮助提供正确的库依赖关系版本以使其正常工作,或者我还缺少其他东西

编辑 从“ org.apache.logging.log4j”中删除的“测试”%“ log4j-core”%“ 2.8.2”
更新build.sbt

"org.slf4j" % "slf4j-api" % "1.6.4","org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.8.2",

今天的关于启用Log4J2 + Apache HttpClient的debugging日志logginglog4jconfiglistener的分享已经结束,谢谢您的关注,如果想了解更多关于004-log-common-logging,Apache整合日志框架JCL门面框架、JCL+log4j、11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using ''c...、Apache httpd请求/响应日志logging、java.lang.NoClassDefFoundError:org / apache / logging / log4j / Logger的相关知识,请在本站进行查询。

本文标签: