Error registering speed on Linux systems

When instatiating Velocity I get this error (only the message "caused" is posted):

java.lang.RuntimeException: Velocity could not be initialized! Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : Caused by: java.io.FileNotFoundException: velocity.log (Permission denied) 

This is my piece of code:

  VelocityEngine ve = new VelocityEngine(); ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString); 

At first, my code looked like this:

 runtimeServices = RuntimeSingleton.getRuntimeServices(); node = runtimeServices.parse(reader, templateName); 

It works fine on my Windows machine, but it doesn't work on Linux systems (ubuntu 10.04). This post does not help me much, since I did not find any clues in which directory I should grant write permissions.

I found out that the following code works on Linux machines too:

 String logPath = request.getRealPath("/velocity.log"); RuntimeSingleton.setProperty( RuntimeConstants.RUNTIME_LOG, logPath ); runtimeServices = RuntimeSingleton.getRuntimeServices(); node = runtimeServices.parse(reader, templateName); 

This is not a good solution, since I was never sure if I have write permission in my real context. It would be best to just turn off Velocity logging.

What other registration configuration should I install? Is NullLogChute just not NullLogChute or am I not using it?

Thanks in advance!

+6
source share
1 answer

Hi, the problem is fs protected by write permission. Infact on your stack that you have:

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

So, good things decide where the speed log will be recorded. And you say a good word, you cannot know whether you can write in a certain way in production. Therefore, it is better to put this path in the properties file, which sysadmin can modify as it sees fit.

So check this answer to another post if you can help.

Link here

0
source

Source: https://habr.com/ru/post/899453/


All Articles