我开始于java和log4j。 我需要帮助我的测试方案。
$pwd
/家庭/家庭/家庭/家庭/家庭/家庭
$ls
log4j. 试验室log4j.java记录_filelogger.xml 运行。
$cat Log4jTest.java
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
public class Log4jTest
{
public static void main(String args[])
{
Logger _log;
String loggerConfig = System.getenv ("logger_config");
if (loggerConfig != null && !loggerConfig.trim ().equals (""))
{
DOMConfigurator.configureAndWatch (loggerConfig);
}
else
{
System.out.println("no logger_config found");
System.exit (-1);
}
System.out.println("Logger is " + Log4jTest.class.getName ());
_log = Logger.getLogger (Log4jTest.class.getName ());
_log.info("logging to logger. Good!");
}
}
页: 1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="threshold" value="OFF" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss,SSS}{GMT+0} [%t] %-5p %c{1} - %m%n" />
</layout>
</appender>
<appender name="log4j_test" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/家庭/家庭/家庭/家庭/家庭/家庭/log_file" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss,SSS}{GMT+0} [%t] %-5p %c{1} - %m%n" />
</layout>
</appender>
<logger name="Log4jTest"
additivity="false">
<level value="INFO" />
<appender-ref ref="log4j_test" />
</logger>
<root>
<level value="INFO" />
<appender-ref ref="log4j_test" />
</root>
$export logger_config=/家庭/家庭/家庭/家庭/家庭/家庭/log_file
jac-cp 途径log4j 试验.java
j-Cp 途径为4j__log4j.jar: 记录 试验
Logger公司 试验
目录记录——档案
Question:
(1) Is it necessary to specify console appender? (2) what goes in root? (3) What does level_value in root as well as loggers do? (4) I was expecting to see: logging to logger. Good!
缩略语
What is going wrong?