更改 Velocity.Log 文件的位置

发布于 2024-11-13 06:22:19 字数 840 浏览 3 评论 0原文

看起来很简单。文档位于 http://velocity.apache.org/engine/devel/developer-guide.html#配置_日志记录 说要设置runtime.log属性。这是我所有财产的所得。

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

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");

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然 2024-11-20 06:22:19

我在运行时设置一些选项时遇到了类似的问题。我通过自定义 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" />

通过这种方式,您可以为不同的文件设置不同的文件日志当您在生产中进行战争时,sysadm 可以根据生产服务器的 env 配置来更改属性。

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

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 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" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文