Linux 系统上速度的日志错误

发布于 2024-12-10 20:35:21 字数 1658 浏览 1 评论 0原文

当初始化 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)

这是我的代码片段:

    VelocityEngine ve = new VelocityEngine();
    ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString);

起初我的代码如下所示:

runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);

在我的 Windows 机器上它工作正常,但在 Linux 系统(ubuntu 10.04)上它不起作用。这篇帖子对我没有多大帮助,因为我还没有找到任何线索我必须授予哪个目录写入权限。

我发现,以下代码也可以在 Linux 机器上运行:

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

这不是一个很好的解决方案,因为我永远无法确定我是否对真实的上下文路径具有写权限。最好的办法是关闭 Velocity 的记录。

我必须设置哪些不同的日志记录配置?是 NullLogChute 不起作用还是我使用它不合适?

提前致谢!

When instatiating Velocity I get this error (posted just the "caused by"-messages):

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. 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:

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.

What different different logging configuration do I have to set? Is the NullLogChute just not working or do I use it inappropriate?

Thanks in advance!

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

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

发布评论

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

评论(1

浪菊怪哟 2024-12-17 20:35:21

您好,问题出在受写权限保护的 fs 上。
事实上,在你的堆栈跟踪中,你有:

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

所以决定将速度日志写入哪里是件好事。
你说得好,你不知道在生产中是否可以写入特定路径。
因此,最好将该路径放在系统管理员可以根据需要修改的属性文件中。

所以请检查我对另一篇文章的回答是否可以帮助您。

链接此处

Hi the problem is on fs protected in write permission.
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.

So check this my answer to another post if can help you.

Link here

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