apache - 更改Velocity.Log文件的位置

标签 apache velocity logfiles

似乎很简单。 http://velocity.apache.org/engine/devel/developer-guide.html#Configuring_Logging上的文档
表示要设置runtime.log属性。这是我所有属性(property)的全部。

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

最佳答案

在运行时设置一些选项时,我遇到了类似的问题。我通过自定义VelocityBuilder和一个外部Velocity.properties文件找出了这些问题,您可以在其中放置所有运行时属性。
这是代码:

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文件,在其中放置了一些配置:
    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'

最后在application.xml中:
    <bean class="applica.framework.library.velocity.BaseVelocityBuilder" />

这样,您可以为例如不同的应用程序使用不同的文件日志,并且在进行生产战时,由于生产服务器的env配置,sysadm可以更改属性。

关于apache - 更改Velocity.Log文件的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6221354/

相关文章:

java - 如何在亚马逊 EC2 中启用 mod_proxy?

php - 从 Web 根目录的子目录中的 CodeIgniter URL 中删除 index.php

Velocity 将 int i = 0 解释为 bool 值 false

java - 在 solr 4.3 中启用基本身份验证

java - Maven 原型(prototype)的速度反射 : get data from Json

javascript - 如何自动对 HTML 表格中共享相同名称的输入值框求和?

Powershell:如何从非常大的文件中流式传输、分页文本?

sql-server - 如何让 SQL Server 跟踪日志文件并将新行写入表?

windows-7 - 应用程序日志文件和用户生成的数据文件应该存储在 APPDATA 还是 PROGRAMDATA 中

apache - 在带有 apache2 的 ubuntu 上使用 SSL 证书导致 ERR_ADDRESS_UNREACHABLE