如何在Log4j中启用Logger.debug() [英] How to enable Logger.debug() in Log4j

查看:136
本文介绍了如何在Log4j中启用Logger.debug()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试执行以下行时,只显示最后两个语句(这里有一些错误和这里有一些致命)并且前三个语句没有显示。我刚刚开始学习这个主题,任何人都可以告诉为什么会发生这种情况?

While trying to execute the following lines only the last two statements are displayed("Here is some ERROR" and "Here is some FATAL") and the first three statements are not displayed.I had just started to learn this topic, can anyone tell why is this happening?

    logger.debug("Here is some DEBUG");
    logger.info("Here is some INFO");
    logger.warn("Here is some WARN");
    logger.error("Here is some ERROR");
    logger.fatal("Here is some FATAL");

log4j.property有

the log4j.property has

log4j.rootLogger=debug,stdout
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{mm:ss}(%F:%M:%L)%n%m%n%n


推荐答案

你可能在项目的某个地方有一个log4j.properties文件。在该文件中,您可以配置所需的调试输出级别。看到这个例子:

You probably have a log4j.properties file somewhere in the project. In that file you can configure which level of debug output you want. See this example:

log4j.rootLogger=info, console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.example=debug

第一行将根记录器的日志级别设置为info,即只有info,warn,error和fatal将打印到控制台(这是在下面定义的appender)。

The first line sets the log level for the root logger to "info", i.e. only info, warn, error and fatal will be printed to the console (which is the appender defined a little below that).

最后一行设置com.example的记录器。*(如果通过 LogFactory.getLogger(getClass()))将处于调试级别,即也将打印调试。

The last line sets the logger for com.example.* (if you get your loggers via LogFactory.getLogger(getClass())) will be at debug level, i.e. debug will also be printed.

这篇关于如何在Log4j中启用Logger.debug()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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