简体   繁体   English

在Linux系统上记录速度错误

[英]Log error in velocity on Linux systems

When instatiating Velocity I get this error (posted just the "caused by"-messages): 当实现Velocity时,我得到了这个错误(仅发布了“由”引起的“消息”):

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 code snippet: 这是我的代码片段:

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

On my Windows machine it works fine, but on Linux systems (ubuntu 10.04) it doesn't work. 在我的Windows机器上它工作正常,但在Linux系统(ubuntu 10.04)上它不起作用。 This post doesn't help me much, since I haven't found any clues which directory I have to give write-permissions. 这篇文章对我帮助不大,因为我没有找到任何线索,我必须给出写入权限。

I found out, that the following code is working also at Linux machines: 我发现,以下代码也适用于Linux机器:

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

It is not a very nice solution, since I could never be sure, if I have write permission on my real context path. 这不是一个非常好的解决方案,因为我无法确定,如果我对我的真实上下文路径有写权限。 The best would be, just turning off logging of Velocity. 最好的是,只关闭Velocity的记录。

What different different logging configuration do I have to set? 我必须设置哪些不同的日志配置? Is the NullLogChute just not working or do I use it inappropriate? NullLogChute是不工作还是我使用它不合适?

Thanks in advance! 提前致谢!

Hi the problem is on fs protected in write permission. 嗨问题是在写入权限受保护的fs上。 Infact in your stacktrace you have: 你的堆栈跟踪实际上你有:

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

So it's good stuff decide where velocity log will be written. 因此,确定速度记录的写入位置是好事。 And you say a good word, you cant know if in production you can write to a specific path. 你说一个好词,你不知道在生产中你是否可以写一个特定的路径。 So it is better put that path in a properties file that sysadmin can modify as he want. 因此,最好将该路径放在sysadmin可以根据需要修改的属性文件中。

So check this my answer to another post if can help you. 如果可以帮到你,请检查我对另一篇文章的回答。

Link here 链接在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM