更改 Velocity.Log 文件的位置

fra*_*nco 5 jboss velocity permission-denied

我使用velocity-1.6.2.jar

我的问题是,velocity.log是在jboss/bin下的服务器上创建的

jboss/bin具有只读权限。

在我的应用程序中,当调用 Velocity-1.6.2.jar 时,我出现以下错误:

Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
Run Code Online (Sandbox Code Playgroud)

我想更改 Velocity.Log 文件的位置

这是我的速度属性中的位置线:

# ----------------------------------------------------------------------------
#  default LogChute to use: default: AvalonLogChute, Log4JLogChute, CommonsLogLogChute, ServletLogChute, JdkLogChute
# ----------------------------------------------------------------------------

runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogChute,org.apache.velocity.runtime.log.Log4JLogChute,org.apache.velocity.runtime.log.CommonsLogLogChute,org.apache.velocity.runtime.log.ServletLogChute,org.apache.velocity.runtime.log.JdkLogChute

# ---------------------------------------------------------------------------
# This is the location of the Velocity Runtime log.
# ----------------------------------------------------------------------------

runtime.log = velocity.log
Run Code Online (Sandbox Code Playgroud)

use*_*900 4

运行时日志可以获得完整路径,因此只需将日志直接记录到您想要的文件夹 /home/velocity.log

 runtime.log = /home/velocity.log
Run Code Online (Sandbox Code Playgroud)

错误、警告和信息性消息的日志文件的完整路径和名称。该位置(如果不是绝对位置)是相对于“当前目录”的。

更新 (27-02-2018)

日志路径也可以通过编程方式设置,如下所示:

import org.apache.velocity.app.VelocityEngine;
public class VelocityCustomEngine extends TemplateEngine {

    private final VelocityEngine velocityEngine;

    public VelocityCustomEngine() {
        Properties properties = new Properties();
        properties.setProperty("runtime.log", "/home/velocity.log");

        this.velocityEngine = new VelocityEngine(properties);
    }
}
Run Code Online (Sandbox Code Playgroud)