log4j2-设置属性问题的文件路径 [英] log4j2 - set file path from properties issue

查看:899
本文介绍了log4j2-设置属性问题的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用xml配置文件从log4j转换为log4j2.一切正常,但似乎无法使用属性文件设置日志文件的路径.

I just converted from log4j to log4j2, using an xml config file. Everything is working except that I can't seem to set the path of my log files using a properties file.

这是Spring MVC应用程序,我在src/main/resources文件夹中有一个filedirs.properties文件,以及log4j2.xml,i18n消息和其他属性文件.它有一个简单的条目:logs=G:/web/logs/.`我浏览了其他文章,只是没有正确地配置log4j2.这是我所拥有的:

This is a Spring MVC app and I have a filedirs.properties file located in the src/main/resources folder along with the log4j2.xml, i18n message and other properties files. It has a simple entry: logs=G:/web/logs/.` I've looked through other posts and am just not getting how to configure log4j2 correctly. Here's what I've have:

<Configuration>
<Properties>
    <Property name="filename">${bundle:net.myapp.filedirs:logs}standard.log</Property>
</Properties>
<File name="stdLog" fileName="${filename}" ignoreExceptions="false">
    <PatternLayout pattern="%d{DEFAULT} %-5p: %c - %m%n"/>
</File>
...rest of config...

错误是这样的:

ERROR FileManager (${bundle:net.myapp.filedir:logs}standard.log) java.io.FileNotFoundException:

替换实际路径,例如

<Property name="filename">g:/web/logs/standard.log</Property>

我迷上了捆绑语法的正确域部分-myapp.net不是实际的网站,但已经足够相似了.我已经尝试了数十种变体,但是在调试模式下,java.util.ResourceBundle在通过log4j2初始化时从未找到filedirs属性文件.手动示例为com.domain.messages,所以我很困惑为什么net.myapp.filedirs无法正常工作.

I'm hung up on the correct domain portion of the bundle syntax - myapp.net is not the actual website, but it's similar enough. I've tried a couple dozen variations but in debug mode java.util.ResourceBundle never finds the filedirs properties file when it goes through the log4j2 initialization. The manual sample is com.domain.messages so I'm stumped why net.myapp.filedirs doesn't work.

推荐答案

正如我在评论中指出的那样,事实证明它确实有效,但是手册可能不正确.代替此处所述的com.domain.messages财产替代,什么工作只是messages,例如<Property name="filename">${bundle:filedir:logs}standard.log</Property>.将status=debug添加到<Configuration>最终帮助我弄清了这一点.

As I indicated in my comment, it turns out that it does work but the manual may be incorrect. Instead of com.domain.messages as described here, Property Substitution, what worked was simply messages, e.g., <Property name="filename">${bundle:filedir:logs}standard.log</Property>. Adding status=debug to <Configuration> finally helped me figure this out.

我不知道这是否有任何区别,但是我正在通过PC上的STS(localhost)进行测试-文档对于生产网站是否可能正确?因为我还没有生产部署,所以不知道,但是当我启动并运行它时,我会检查一下.

I don't know if this makes any difference, but I'm testing through STS (localhost) on my PC - is it possible the documentation may be correct for a production website? No idea since I don't have a production deployment yet but it's something I'll check out when I get it up and running.

这篇关于log4j2-设置属性问题的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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