简体   繁体   English

log4j2-从属性问题设置文件路径

[英]log4j2 - set file path from properties issue

I just converted from log4j to log4j2, using an xml config file. 我只是使用xml配置文件从log4j转换为log4j2。 Everything is working except that I can't seem to set the path of my log files using a properties file. 一切正常,但似乎无法使用属性文件设置日志文件的路径。

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. 这是一个Spring MVC应用程序,我在src/main/resources文件夹中有一个filedirs.properties文件,以及log4j2.xml,i18n消息和其他属性文件。 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. 它有一个简单的条目: logs=G:/web/logs/ 。我看过其他文章,只是没有正确地配置log4j2。 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...

The error is this: 错误是这样的:

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

Substituting the actual path works, eg, 替代实际路径,例如

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

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. 我迷上了捆绑语法的正确域部分-myapp.net不是实际的网站,但足够相似。 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. 我尝试了几十种变体,但是在调试模式下,java.util.ResourceBundle在通过log4j2初始化时从未找到filedirs属性文件。 The manual sample is com.domain.messages so I'm stumped why net.myapp.filedirs doesn't work. 手动示例是com.domain.messages因此我很net.myapp.filedirs为什么net.myapp.filedirs不起作用。

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 , eg, <Property name="filename">${bundle:filedir:logs}standard.log</Property> . 代替此处描述的com.domain.messages属性替换) ,起作用的只是messages ,例如<Property name="filename">${bundle:filedir:logs}standard.log</Property> Adding status=debug to <Configuration> finally helped me figure this out. status=debug添加到<Configuration>最终帮助我弄清楚了这一点。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM