更改 Velocity.Log 文件的位置



我使用了velocity-1.6.2.jar

我的问题 速度.log 是在服务器上创建的 JBoS/bin 下启动的

JBoss/bin 具有只读权限。

在我的应用程序中,当速度 1.6.2.jar 将被调用时,我有这个错误:

Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)

我想更改 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

运行时日志可以获得完整路径,因此只需将日志定向到所需的文件夹为/home/velocity.log

 runtime.log = /home/velocity.log

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

更新 (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);
    }
}
我知道

有一个答案。如果您不想扩展原始的速度引擎。您还可以新建一个 VelocityEngine 实例,仅在 init() 方法之前更改了"runtime.log"属性,而没有任何新类。

        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty("runtime.log", "/home/velocity.log");
        velocityEngine.setProperty(RuntimeConstants.ENCODING_DEFAULT, "UTF-8");
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        velocityEngine.init();//init method will use the properties(include the log file location) actually.
        return velocityEngine;

最新更新