5

I used velocity-1.6.2.jar

my problem that velocity.log is created on the server start under jboss/bin

jboss/bin has read only permission.

and in my appilcation when velocity-1.6.2.jar will be called I have this error:

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

I want to change the location of Velocity.Log File

This is the location line in my velocity properties:

# ----------------------------------------------------------------------------
#  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
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
franco
  • 1,829
  • 6
  • 42
  • 75

2 Answers2

4

Runtime log can get full path so just direct log to your desrirable folder as /home/velocity.log

 runtime.log = /home/velocity.log

Full path and name of log file for error, warning, and informational messages. The location, if not absolute, is relative to the 'current directory'.

Update (27-02-2018)

The log path can also be set programmatically as following:

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);
    }
}
crazyGuy
  • 338
  • 2
  • 15
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
2

I know there's an answer. In case you don't want to extend the original VelocityEngine. You can also new a VelocityEngine instance only changed the "runtime.log" properties before the init() method without any new class.

        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;
Ron
  • 903
  • 2
  • 11
  • 20