我们花了很多时间开发自己的自定义日志记录系统(对或错,这就是高层决定的!)我被要求编写自定义SLF4J绑定(API实现)以便我们的许多SLF4J利用组件(例如Apache Camel)将开始记录到我们新的本地系统.
我按照SLF4J网站上的说明操作了"T",创建:
StaticLoggerBinder是SLF4J使用在运行时绑定Loggers和LoggerFactory类org.slf4j.Logger呼叫一切都很好.我将它装罐并将其添加到lib测试项目的目录中,以及slf4j-api-1.6.2.jar(他们希望我使用的版本).我在Eclipse中的构建路径中添加了两个JAR.
我为测试项目创建了一个新的运行配置,在Run Configuration的Classpath选项卡窗格中,我看到它有User Entries >> TestBinding >> Slf4jBinding.jar and slf4j-api-1.6.2.jar.
因此,似乎两个JAR都在Run Configuration的类路径中.
在项目中运行看起来像这样的驱动程序:
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(TestDriver.class);
logger.error("Test");
}
Run Code Online (Sandbox Code Playgroud)
我得到以下运行时错误:
SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder".SLF4J:默认为无操作(NOP)记录器实现SLF4J:有关更多详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder.
去那个被引用的网站,似乎SLF4J找不到我StaticLoggerBinder在类路径上Slf4jBinding.jar,虽然不是在JAR的根级别.
我查看了SLF4J的LoggerFactory.java源文件,发现抛出此类错误的代码:
private final static void bind() {
try {
// the next line does the binding
StaticLoggerBinder.getSingleton();
INITIALIZATION_STATE = SUCCESSFUL_INITILIZATION;
emitSubstituteLoggerWarning();
} …Run Code Online (Sandbox Code Playgroud) 我正在使用JUnit构建一些测试用例来测试我的应用程序,但是当我尝试运行它们时,我得到错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Run Code Online (Sandbox Code Playgroud)
问题是当我运行我的应用程序时,我没有得到那个错误,就在我运行测试用例时......
我的应用程序是用Spring + Hibernate + Java 6构建的
以下是我在pom.xml文件中获得的依赖项:
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- Dependencias Spring -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Spring security -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId> …Run Code Online (Sandbox Code Playgroud) 我的问题更多与" 强制Jboss记录使用SLF4J "有关,但无法在其中找到更多详细信息,所以我再次在此处发布.如何使slf4j工作,如果我的一个类调用slf4j我得到以下错误.由于jboss 7.1.1已经有了slf4j模块,我需要添加什么才能使它工作.
20:20:31,565 ERROR [stderr] (MSC service thread 1-8) SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
20:20:31,572 ERROR [stderr] (MSC service thread 1-8) SLF4J: Defaulting to no-operation (NOP) logger implementation
20:20:31,578 ERROR [stderr] (MSC service thread 1-8) SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Run Code Online (Sandbox Code Playgroud) 我在maven项目中使用jetty,并且已经使用slf4j和logback进行日志记录.因此,我有一个logback.xml,我配置日志记录,它到目前为止工作(格式,我的项目和库的设置级别,......).
但是,现在我在pom.xml中添加了jetty作为依赖项,我得到了大量新的DEBUG日志,我不想看到(通常).
如何将jetty的日志级别设置为更高级别?
一开始,jetty报告说它认可了slf4j:
13:08:57 [main] [DEBUG] log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog
Run Code Online (Sandbox Code Playgroud)
在我的logback.xml中,我尝试将jetty静音如下,但它不起作用:
<logger name="org.eclipse.jetty" level="INFO" />
Run Code Online (Sandbox Code Playgroud)
这为我使用的其他库提供了技巧.
我有一个Groovy库,使用@Slf4jGroovy提供的注释进行记录:
@Slf4j
class SomePogo {
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
如果我将这个lib放到Grails(2.4.2)应用程序中,默认的基于log4j的日志记录系统是否会在这些类中获取日志语句?或者我是否需要将log4j记录器添加到我的所有类中?
我正在尝试在Spring Web应用程序中从迁移log4j 1到log4j 2。构建它时,出现以下错误:
2015-08-10 16:26:36,222 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-08-10 16:26:36,222 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for builder factory method...
2015-08-10 16:26:36,222 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger. Going to try finding a factory method instead.
2015-08-10 16:26:36,223 DEBUG Still building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for factory method...
2015-08-10 16:26:36,223 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig$RootLogger.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-08-10 16:26:36,224 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root …Run Code Online (Sandbox Code Playgroud) 我正在尝试同时使用slf4j和log4j。经过一番谷歌搜索,我找到了一些解决方案:
与slf4j和log4j相关的jar的各种名称和版本让我非常困惑。slf4j-log4j12,log4j,log4j-core,log4j-over-slf4j,log4j-slf4j-impl,log4j-api,slf4j-impl,log4j12-api,log4j-to-slf4j ............我什至无法了解这些不同罐子的功能。
那么,我应该选择哪种组合和版本?
我看到logback异步日志记录提供的性能比同步日志记录差.详情如下.
我能错过什么?
测试类:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main extends Thread {
public static final Logger defaultLogger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws IOException {
new Main().start();
System.out.println("... Thread started\n");
// This is to block till thread finishes writing
System.in.read();
}
public void run() {
long start = System.currentTimeMillis();
for(int i = 0; i < 1000000; i++) {
defaultLogger.warn("Default logger:");
}
long end = System.currentTimeMillis();
System.out.println("\n**** " + new Long(end - start));
}
}
Run Code Online (Sandbox Code Playgroud)
logback.xml:
<configuration>
<appender …Run Code Online (Sandbox Code Playgroud) 在尝试记录依赖项时,我遇到以下情况:
<repositories>
<repository>
<id>version99</id>
<url>http://version99.qos.ch/</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>99-empty</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!--<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.25</version>
</dependency>-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
值得注意的是,依赖关系jcl-over-slf4j被注释掉了.令我惊讶的是,来自Spring的日志仍由Logback处理.这怎么可能?jcl和slf4j之间没有活动桥,那么我们如何才能在Logback中结束?
我证实了这一点:
commons-logging-99-empty.jar在classpath中.jcl-over-slf4j提到mvn dependency:tree -Dverbose -Dincludes=org.slf4j我真的很困惑.我期待NoClassDefFoundError上课commons-logging.
请注意,我无意jcl-over-slf4j在评论中留下这种依赖.我只是想了解发生了什么.我以为我终于明白了这些日志依赖,但显然,在实践中,它的行为完全不同于我的预期.
我有这个配置:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>1.0.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
name=PropertiesConfig
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
rootLogger.level = ERROR
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
Run Code Online (Sandbox Code Playgroud)
当我开始使用Kafka消费者时org.apache.kafka.clients.consumer.KafkaConsumer,它会在该INFO级别进行记录.我创建的任何新记录器都使用LogManager.getLogger(name)了级别的配置和日志ERROR,因此我知道log4j2.properties正在加载和使用该文件.卡夫卡似乎无视它.在日志中,当Kafka消费者启动时,我会看到这一行:
Aug 20, 2018 11:03:37 PM org.apache.kafka.common.utils.LogContext$KafkaLogger info
任何帮助赞赏!