我有一个使用hibernate-annotations 3.4.0.GA的maven项目A,它使用slf4j-api 1.5.5版(通过pom.xml文件中的依赖树检查).进一步的项目A将slf4j-log4j12版本1.4.2指定为依赖项.
我有另一个依赖项目A的maven项目B.在项目BI中指定了以下依赖项:
slf4j-api version 1.6.1,
logback-core version 0.9.24
logback-classic version 0.9.24
Run Code Online (Sandbox Code Playgroud)
从命令行使用maven构建良好.但是当我从eclipse启动配置运行项目时,我得到:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/org/slf4j/slf4j-log4j12/1.4.2/slf4j-log4j12-1.4.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/mm/.m2/repository/ch/qos/logback/logback-classic/0.9.24/logback-classic-0.9.24.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
Run Code Online (Sandbox Code Playgroud)
从这条消息中我指出我需要将项目A中的绑定升级到1.6.x,但是我没有看到它是如何可能的,因为它包含在hibernate依赖项中.
是否可以在运行项目B时切换绑定(更新类路径信息),以便它使用1.6.1版本而不是hibernate项目中的版本?
我正在写一个库,我使用sfl4j来处理日志.
我认为这是个好主意,只要每个机构都能提供它自己的实现,然后,我的应用程序提供的日志将被正确处理.
但我不知道是否必须提供实现作为传递依赖.
例:
如果我只提供:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的lib的用户可以选择实现,但如果他只是添加我的lib而没有读取配置,它将无法工作
否则,如果我提供:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的lib只在向它添加依赖项时才能正常工作,但是如果用户想要使用其他slf4j,他将不得不排除我的.
你对此有何看法?
我花了一整天的时间来尝试解决我在webapp中使用log4j的日志记录问题.无论我做什么,我都无法摆脱以下几点:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,我已经阅读了Stack Overflow上有关此问题的所有文章.我已经阅读了log4j手册.我经历了十几个不同的教程.我尝试过属性方法和XML方法(分别是log4j.properties和log4j.xml).此外,我已确认正在读取log4j.xml文件.除了服务器在启动期间告诉我的事实,我可以通过.xml文件影响反馈级别.所以,是的,log4j.xml文件位于CLASSPATH中.
我知道我错过了一些简单而基本的东西.以下是相关文件:
LOG4J.XML(/ WEB-INF):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Application Loggers -->
<logger name="com.tiersoftinc.testlog">
<level value="info" />
</logger>
<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
<level value="info" /> …Run Code Online (Sandbox Code Playgroud) SLF4J(1.7.5,但实际上是任何现代版本)附带了几个"over"(迁移器)JAR:
jcl-over-slf4j-1.7.5.jarlog4j-over-slf4j-1.7.5.jar......以及"to"(桥梁)JAR:
jul-to-slf4j-1.7.5.jar根据他们的文档,迁移者:
...从[JCL/log4j]轻松[s]迁移到SLF4J.此jar文件旨在作为[JCL/log4j]的替代品.它实现了[ir]公共API但在下面使用SLF4J,因此名称"over"SLF4J.
而JUL桥:
将所有传入的jul记录路由到SLF4j API.
jcl-over-slf4j-1.7.5.jar的时候我有一个记录使用JCL代码,但我想它使用SLF4J?或者是其他东西?jul-to-slf4j-1.7.5.jar什么时候用?这里的"to"一词与"over"的使用方式有何不同?是否可以通过«Logging and tracing»菜单在WebSphere 7 Application Server上的运行时配置日志记录级别?
我使用slf4j-log4j12和jcl-over-slf4j.
对于前者 我有以下log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Root Logger -->
<root>
<priority value="TRACE" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
Run Code Online (Sandbox Code Playgroud)
log4j配置将大量调试和跟踪信息输出到SystemOut.log文件中.喜欢:
[10/21/13 16:31:18:141 FET] 0000001a SystemOut O DEBUG:org.springframework.core.convert.support.GenericConversionService - 转换为'10/21/14'[10/21/13 16:31 :18:141 FET] 0000001a SystemOut O TRACE:org.springframework.core.convert.support.GenericConversionService - 检查我是否可以将java.lang.String转换为@ org.springframework.format.annotation.DateTimeFormat @ javax.validation.constraints .Future java.util.Date
所以,我试着添加这一行:
org.springframework.*=info
Run Code Online (Sandbox Code Playgroud)
但是,它不会影响我的Web应用程序的日志级别.
最近添加了一些println输出到我的程序...现在不希望与它们合并的logback INFO消息.如何将所有消息发送到stderr?
我有application.yml,代码如下:
logging:
file: logs/keyserver.log
level:
org.springframework.web: 'DEBUG'
Run Code Online (Sandbox Code Playgroud)
它工作正常,除了这种情况:
public class TransactionBuilder extends Wallet {
private final Logger LOG = LoggerFactory.getLogger(TransactionBuilder.class);
@Override
public RedeemData findRedeemDataFromScriptHash(byte[] payToScriptHash) {
LOG.debug("payToScriptHash = " + HEX.encode(payToScriptHash));
}
}
Run Code Online (Sandbox Code Playgroud)
消息既不出现在日志文件中也不出现在屏幕上.
然而
LOG.info("payToScriptHash = " + HEX.encode(payToScriptHash));
LOG.error("payToScriptHash = " + HEX.encode(payToScriptHash));
Run Code Online (Sandbox Code Playgroud)
工作得很好.
我正在Tomcat 8.0.22上部署Shibboleth IdP 3.1.1,但是我收到此错误:
SEVERE [http-nio-8080-exec-13] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.shibboleth.ext.spring.context.DeferPlaceholderFileSystemXmlWebApplicationContext]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:360)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用logback登录我的应用程序,并且在运行该应用程序时,我不断收到以下警告。当我运行单元测试时,它会在每堂课上打印出来!
SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: com.kohls.kube.service.sdk.logging.CustomAppender
SLF4J: com.kohls.kube.service.sdk.logging.appender.mqtt.messaging.ClientMqttImpl
SLF4J: com.kohls.service.sdk.messaging.TCPMessager
SLF4J: com.kohls.service.sdk.logging.appender.mqtt.MQTTAppender
SLF4J: com.kohls.service.sdk.messaging.EdgeNodeMessager
SLF4J: com.kohls.service.sdk.messaging.SubscriptionTask
Run Code Online (Sandbox Code Playgroud)
我已经配置了logback,以在某个位置查找配置文件,下面是日志工厂类的外观。
public class LoggerFactory {
static {
System.setProperty("logback.configurationFile", System.getProperty("user.dir") + "\\" + "logbackConfig.xml");
}
private LoggerFactory() {
}
public static Logger getLogger(Class className) {
return …Run Code Online (Sandbox Code Playgroud) 我是slf4j / logback的新手,所以我有几个问题。主要的是,我可以同时将其打印到控制台和日志文件吗?
目前,我可以将其打印到日志文件。这是logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
<file>/Users/admin/testlogs/myLogFile.log</file>
<append>true</append>
<encoder>
<pattern>%d [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="fileAppender" />
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在程序中,如果我有以下命令:
slf4jLogger2.warn("test");
Run Code Online (Sandbox Code Playgroud)
它将以下输出放入日志文件:
2018-02-03 21:21:10,145 [Thread name] WARN c.s.a.t.s.MyProgram - test
Run Code Online (Sandbox Code Playgroud)
我的主要问题是,如何将其也添加到控制台?
另外,是否可以像在printf语句中那样将格式化的数据放入消息中?
例如,
out.printf("Sent: (%.2f/sec for %.1f |seconds)%n", floatPerSec, elTime);
Run Code Online (Sandbox Code Playgroud) slf4j ×10
java ×6
logging ×5
log4j ×3
logback ×3
appender ×1
console ×1
eclipse ×1
hibernate ×1
maven ×1
maven-2 ×1
shibboleth ×1
spring ×1
spring-boot ×1
spring-mvc ×1
tomcat ×1
websphere-7 ×1