GlassFish 4,pom.xml中没有日志记录框架依赖项 [英] GlassFish 4, no logging framework dependencies is working in pom.xml

查看:84
本文介绍了GlassFish 4,pom.xml中没有日志记录框架依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个spring mvc项目库都使用其自己的日志记录框架viz. log4j,slf4j,logback,jboss-logging,commons-logging等,如下所示,并带有Maven集成.

Each spring mvc project library uses its own logging framework viz. log4j, slf4j, logback, jboss-logging, commons-logging etc. as given below with maven integration.

pom.xml

<log4j.version>1.6.5</log4j.version>
<slf4j.version>1.7.16</slf4j.version>
<slf4j.log4j13.version>1.0.1</slf4j.log4j13.version>
<logback.version>1.1.2</logback.version>
<jboss.logging.version>3.3.0.Final</jboss.logging.version>
<commons.logging.version>1.2</commons.logging.version>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-bom</artifactId>
      <version>2.5</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
<dependency>
    <groupId>ant</groupId>
    <artifactId>ant-jakarta-log4j</artifactId>
    <version>1.6.1</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>

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

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

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>${slf4j.log4j13.version}</version>
</dependency>

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

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

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

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>  
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
</dependency>
</dependencies>

这是在运行项目时显示的严重错误

Here is the Severe Error displayed while running the project

SLF4J:类路径包含多个SLF4J绑定.

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J:在[jar:file:/WEB-INF/lib/log4j-slf4j-impl-2.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定

SLF4J: Found binding in [jar:file:/WEB-INF/lib/log4j-slf4j-impl-2.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J:在[jar:file:/WEB-INF/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定

SLF4J: Found binding in [jar:file:/WEB-INF/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J:在[jar:file:/WEB-INF/lib/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J:在[jar:file:/WEB-INF/lib/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J:实际绑定的类型为[org.apache.logging.slf4j.Log4jLoggerFactory] ​​

SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

错误StatusLogger找不到log4j2配置文件.使用默认配置:仅将错误记录到控制台.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

要包含该项目,需要每个日志记录框架.但是有什么技巧可以在运行项目时保留外部库所需的日志记录框架,而不会出现错误.

Each logging framework is needed for the project to be included. But is there any trick to retain the logging framewokrs needed by the external libraries while running the project without errors.

推荐答案

通常,您将具有多个组件,每个组件使用不同的日志记录API.通常,您要做的是将每个绑定到特定的日志记录实现中.例如,Spring使用commons-logging,因此要将其路由到Log4j 2,您将包括log4j-jcl jar.同样,要将SLF4J路由到Log4j 2,您将包括log4j-slf4j-impl jar.您将不包括任何Logback jar,因为它是另一个日志记录实现.在上述错误的情况下,您将得到显示SLF4J具有Log4j 2 SLF4J绑定,logback,log4j1.2绑定和log4j 1.3绑定.您应该只有1个,所以请删除不想使用的罐子.

Typically you will have multiple components that each use different logging APIs. What you normally want to do is bind each of those with a specific logging implementation. For example, Spring uses commons-logging so to route it to Log4j 2 you would include the log4j-jcl jar. Likewise, to route SLF4J to Log4j 2 you would include the log4j-slf4j-impl jar. You would not include any Logback jars since it is another logging implementation. In the case above the errors you are getting show that you have the Log4j 2 SLF4J binding, logback, log4j1.2 binding and log4j 1.3 bindings for SLF4J. You should only have 1 of them, so remove the jars for the ones you don't want to use.

请注意,SLF4J告诉您它选择了Log4j 2绑定,但是随后您从Log4j 2中收到一条错误消息,通知您找不到配置文件-通常为log4j2.xml.

Note that SLF4J is telling you that it chose the Log4j 2 binding but then you are getting an error from Log4j 2 informing you that it can't find a configuration file - typically this would be log4j2.xml.

这篇关于GlassFish 4,pom.xml中没有日志记录框架依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆