Logger.info不会向控制台写任何内容

时间:2014-05-22 23:09:40

标签: java apache logging error-logging

您好我的代码如下 -

public class testSmthing extends Base{


    private Logger logger = Logger.getLogger(TestFirewallACL.class);        


    @BeforeMethod(alwaysRun = true)
    public void setUp() 
    {
        try
        {
            //logger.setLevel(Level.DEBUG);
            logger.info("Initializing  Client");
            super.setUp();
        }
        catch(Throwable e)
        {
            //
        }
    }


    @Test(groups="test")
    public void testSmthing()
    {
        String payload  = getPayload("d.xml");

    }
}

我的问题是,当我运行这个时,我无法看到logger.info中写的任何内容。 还有其他我需要做的事情。

1 个答案:

答案 0 :(得分:0)

在classpath中添加了log4j.properties

# For the general syntax of propperty based configuration files see
# the documenation of org.apache.log4j.PropertyConfigurator.

# The root category uses two appenders: default.out and default.file.
# The first one gathers all log output, the latter only starting with 
# the priority INFO.
# The root priority is DEBUG, so that all classes can be logged unless 
# defined otherwise in more specific properties.
log4j.rootLogger=DEBUG, default.out, default.file

# System.out.println appender for all classes
log4j.appender.default.out=org.apache.log4j.ConsoleAppender
log4j.appender.default.out.threshold=DEBUG
log4j.appender.default.out.layout=org.apache.log4j.PatternLayout
log4j.appender.default.out.layout.ConversionPattern=%-5p %c: %m%n

log4j.appender.default.file=org.apache.log4j.FileAppender
log4j.appender.default.file.append=true
log4j.appender.default.file.file=/log/mylogfile.log
log4j.appender.default.file.threshold=INFO
log4j.appender.default.file.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.layout.ConversionPattern=%-5p %c: %m%n