问题描述
我是编程概念的新手,我倾向于用log4j来处理东西。所以我正在阅读Log4j教程,在那里我找到以下代码: 包测试;
import org.apache.log4j.Logger;
import java.io. *;
import java.sql.SQLException;
public class Log4jExample {
/ *获取要打印在* /
上的实际类名静态Logger log = Logger.getLogger(Log4jExample。 class.getName());
public static void main(String [] args)throws IOException,SQLException
{
log.debug(Hello this is a debug message);
log.info(Hello this is a info message);
}
}
但是在eclipse中运行无法找到生成的日志文件。任何人都可以告诉文件被转储在哪里?也帮助我一些最好的网站,从那里我可以从头开始学习Log4j和Java Doc。谢谢!!
要将日志输出重定向到文件,您需要使用FileAppender并需要定义其他文件详细信息在你的log4j.properties/xml文件中。以下是相同的示例属性文件:
#根记录器选项
log4j.rootLogger = INFO,文件
#将日志消息直接发送到日志文件
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File = C:\\ loging.log
log4j.appender.file.MaxFileSize = 1MB
log4j.appender.file.MaxBackupIndex = 1
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern =%d {yyyy-MM-dd HH:mm:ss}%-5p%c {1}:%L - %m%n
按照本教程了解有关log4j用法的更多信息:
Hi i am new to programming concepts and i am tend to work out something with log4j. So i am reading Log4j tutorials where i found the following code:
package test;
import org.apache.log4j.Logger;
import java.io.*;
import java.sql.SQLException;
public class Log4jExample {
/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(Log4jExample.class.getName());
public static void main(String[] args)throws IOException,SQLException
{
log.debug("Hello this is an debug message");
log.info("Hello this is an info message");
}
}
But after running this in eclipse i am not able to locate the generated log file. Can anybody tell where is the file being dumped? Also help me with some best sites wherefrom i can learn Log4j and Java Doc from the scratch. Thanks!!
To redirect your logs output to a file, you need to use the FileAppender and need to define other file details in your log4j.properties/xml file. Here is a sample properties file for the same:
# Root logger option
log4j.rootLogger=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Follow this tutorial to learn more about log4j usage:
http://www.mkyong.com/logging/log4j-log4j-properties-examples/
这篇关于什么是log4j的默认日志文件转储路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!