Search code examples
jbossvelocitypermission-denied

Change the Location of Velocity.Log File


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

Solution

  • 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);
        }
    }