Change the location of the Velocity.Log file

Seems pretty straight forward. The documentation at http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Logging says to set the runtime.log property. This is what I got for all my properties.

velocityEngine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatesPath); velocityEngine.setProperty("runtime.log", "/path/to/my/file/velocity.log"); velocityEngine.setProperty("resource.loader", "string"); velocityEngine.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); velocityEngine.setProperty("string.resource.loader.repository.class", "org.apache.velocity.runtime.resource.util.StringResourceRepositoryImpl"); 

Do not find the log file where I told him to place it, and instead find new errors placed in the old (folder of initialization) folder. Any ideas ?: D

+5
source share
1 answer

I had a similar problem while setting up while executing some parameters. I figured out this problem with a custom VelocityBuilder and an external velocity.properties file where you can put all the runtime properties. Here is the code:

 public class BaseVelocityBuilder implements VelocityBuilder { private VelocityEngine engine; private Log logger = LogFactory.getLog(getClass()); @Autowired private WebApplicationContext webApplicationContext; public VelocityEngine engine() { if(engine == null) { engine = new VelocityEngine(); Properties properties = new Properties(); InputStream in = null; try { in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties"); properties.load(in); engine.init(properties); } catch (IOException e) { e.printStackTrace(); logger.error("Error loading velocity engine properties"); throw new ProgramException("Cannot load velocity engine properties"); } IOUtils.closeQuietly(in); } return engine; } } 

See this line:

  in = webApplicationContext.getServletContext().getResourceAsStream("/WEB-INF/velocity.properties"); properties.load(in); engine.init(properties); 

So, I have a velocity.properties file in / WEB -INF, where I added some configuration:

  resource.loader = webinf, class webinf.resource.loader.description = Framework Templates Resource Loader webinf.resource.loader.class = applica.framework.library.velocity.WEBINFResourceLoader webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader webapp.resource.loader.path = file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.path = class.resource.loader.description = Velocity Classpath Resource Loader class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader runtime.log='/pathYouWant/velocity.log' 

At the end of your .xml application:

  <bean class="applica.framework.library.velocity.BaseVelocityBuilder" /> 

Thus, you can have, for example, a different log file for different applications, and when you give war on production, sysadm can change properties due to the env configuration on the production server.

+1
source

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


All Articles