Velocity.Log改变文件的位置 [英] Changing Location of Velocity.Log File

查看:2207
本文介绍了Velocity.Log改变文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像pretty直线前进。在 http://velocity.apache.org/engine/devel/developer文档-guide.html#Configuring_Logging
说来设置runtime.log属性。下面是我为我的所有属性。

Seems pretty straight forward. Documentation at http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Logging says to set the runtime.log property. Here's 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");

没有找到任何日志文件,其中我告诉它把它转而寻找放到原来的位置(初始化文件夹)的新的错误。有任何想法吗? :D

Not finding any log file where I told it to place it and instead finding the new errors placed into old (folder of initialization) location. Any ideas? :D

推荐答案

在运行时的一些选项设置当我有类似的问题。我想通了这些问题丝毫定制VelocityBuilder和外部velocity.properties文件,你可以把所有的运行属性。
这里是code:

i had similar problem when setting at runtime some options. I figured out those problem whit 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;
    }
}

请参阅此行:

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

所以我在/ WEB-INF一个velocity.properties文件,其中我把一些配置:

So i have a velocity.properties file in /WEB-INF where i put 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'

在在中的应用程序到底:

In the end in your application.xml :

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

在这种方式,你可以有例如不同的文件日志针对不同的应用,当你给生产战争中,SYSADM可以更改的属性,由于生产服务器的ENV配置。

In this way you can have for example different file log for different application and when you give the war in production, the sysadm can change the properties due to env configuration of the production server.

这篇关于Velocity.Log改变文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆