log4j2 - set file path from properties issue

和自甴很熟 提交于 2019-12-12 03:57:17

问题


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.

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...

The error is this:

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

Substituting the actual path works, e.g.,

<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. 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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/35386080/log4j2-set-file-path-from-properties-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!