openfire的日志可以通过/usr/openfire/lib/log4j.xml(与openfire的安装目录有关,我的openfire是安装在/usr/openfire/)的xml配置文件进行设定logs文件的位置,但是我在对openfire的进行日志文件配置后(通过设定openfireHone环境变量值export openfireHome=/usr/openfire),一直无法在/usr/openfire/logs/目录下生成info.log、debug.log、error.log、warn.log几个日志文件,直到昨天才发现在日志文件生成在根目录下的logs文件夹即/logs/。网上说openfireHome的环境变量值,但实际上我已经在/etc/profild中设置了export openfireHome=/usr/openfire环境变量值。但是openfire运行时,{$openfireHome}的值为空的,${openfireHome}/logs/debug.log替换后变成/logs/debug.log。为了让日志文件生成在/usr/openfire/logs中,我测试了两种实现方式。
- 设定相对路径
把<param name="File" value="${openfireHome}/logs/debug.log" />中的值改为<param name="File" value="../logs/debug.log" />,以此类推。
- 设定绝对路径
把<param name="File" value="${openfireHome}/logs/debug.log" />中的值改为<param name="File" value="/usr/logs/debug.log" />,以此类推,不过个人不建议设定成绝对路径,还是使用相对路径实现。
- 设定环境变量方式
网上介绍设定openfireHome环境变量值,就可以实现定义openfire的日志路径,个人认为这种方式最好,但是我没有测试成功,有待后续继续研究。
- 原始的log4j.xml的内容
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="debug-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${openfireHome}/logs/debug.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="debug" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="info-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${openfireHome}/logs/info.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="info" /> <param name="LevelMin" value="info" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="warn-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${openfireHome}/logs/warn.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="warn" /> <param name="LevelMin" value="warn" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="error-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${openfireHome}/logs/error.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="error" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <!-- OF-506: Jetty INFO messages are generally not useful. Ignore them by default. --> <logger name="org.eclipse.jetty"> <level value="warn" /> </logger> <root> <level value="info" /> <appender-ref ref="debug-out" /> <appender-ref ref="info-out" /> <appender-ref ref="warn-out" /> <appender-ref ref="error-out" /> </root> </log4j:configuration>
- 设定为相对路径的log4j.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="debug-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="../logs/debug.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="debug" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="info-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="../logs/info.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="info" /> <param name="LevelMin" value="info" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="warn-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="../logs/warn.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="warn" /> <param name="LevelMin" value="warn" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <appender name="error-out" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="../logs/error.log" /> <param name="MaxFileSize" value="1024KB"/> <param name="MaxBackupIndex" value="5"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy.MM.dd HH:mm:ss} %c - %m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="error" /> <param name="AcceptOnMatch" value="true" /> </filter> </appender> <!-- OF-506: Jetty INFO messages are generally not useful. Ignore them by default. --> <logger name="org.eclipse.jetty"> <level value="warn" /> </logger> <root> <level value="info" /> <appender-ref ref="debug-out" /> <appender-ref ref="info-out" /> <appender-ref ref="warn-out" /> <appender-ref ref="error-out" /> </root> </log4j:configuration>