导航:首页 > 文件教程 > 创建log4jproperties文件

创建log4jproperties文件

发布时间:2024-11-26 02:44:21

㈠ 请问,在eclipse spring如何添加配置文件

log4j.properties,放在项目的scr目录下
log4j.properties是要自己写的(新建一个log4j.properties文件),网上有很多参考模板.
配置回文件是xml格式的,在程序里答面调用就可以了(注意路径)

㈡ log4j的使用步骤

1.将log4j-1.2.14.jar加入你的项目中;
2.在src/下创建log4j.properties|log4j.xml文件;
3.在web.xml中配置log4j的信息,如下:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
4.在项目webroot下创建你想要保存日志文件的文件夹及文件,如webroot/logs/web_app.log;
具体log4j.properties文件,给你一个示例吧,如下:
log4j.rootLogger=INFO, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.stdout.layout.ConversionPattern=- %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${webapp.root}/logs/webapp.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

log4j.logger.com.opensymphony.xwork2=ERROR

# Control logging for other open source packages
log4j.logger.org.springframework=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.net.sf.ehcache=ERROR
log4j.logger.net.sf.navigator=ERROR
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.apache.struts=ERROR

# Struts OgnlUtil issues unimportant warnings
log4j.logger.com.opensymphony.xwork2.util.OgnlUtil=error
log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack=error
具体写法可根据自己的项目进行配置。

㈢ log4j.properties配置文件是在什么地方调用读取的呢

一般在项目中使用properties配置文件的时候都将相关的properties文件放在src目录下,在将该app打包生成jar后,相应的properties配置文件生...
一般在项目中使用properties配置文件的时候都将相关的properties文件放在src目录下,在将该app打包生成jar后,相应的properties配置文件生成在jar包中,这样的话要修改配置文件又要重新打jar包,那是相当的麻烦。
既然这么麻烦,你肯定想将配置文件放在其他的目录下,生成的jar包内不包含相应的配置文件,修改配置文件无需重新打包,没错,下面就是一种解决方案了。
读取jar包内配置文件:

InputStream in = this.getClass().getClassLoader().getResourceAsStream("/configfilename.properties");
读取jar包外配置文件:

String filePath = System.getProperty("user.dir") + "/conf/configfilename.properties";
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
另外,如果app中使用到log4j.properties文件,默认的存放路径是src/log4j.properties,同上面一样,我想把log4j.properties放在其他目录中,这样一来,在修改log4j配置文件的时候无需重新打jar包。
在main函数第一行添加如下代码
PropertyConfigurator.configure(System.getProperty("user.dir") + "/conf/log4j.properties");

阅读全文

与创建log4jproperties文件相关的资料

热点内容
血压计校正数据多少钱 浏览:779
吴江区学数控编程哪里有 浏览:607
3dmax自然光教程 浏览:426
起名网站源码 浏览:856
编程怎么让一根针转动 浏览:556
java代码异常如何定位 浏览:959
软件工程需要什么编程 浏览:804
手机测评网站哪个权威 浏览:81
搜狐网站源码下载 浏览:302
如何举报恶性app 浏览:835
一个虚拟主机怎么建多少网站 浏览:825
和家亲app为什么老是掉线 浏览:990
儿童编程思维课有什么用 浏览:600
魔百和网络机顶盒怎么连接电视 浏览:611
国产显示器icc配置文件 浏览:52
java编程常见的语法糖有哪些 浏览:41
jspmysql选课源码 浏览:877
ipadmini2下载app等待 浏览:399
creo工程图配置文件 浏览:699
编程和钢琴哪个贵 浏览:841

友情链接