linux - 在 Linux 系统上记录速度错误

标签 linux logging velocity

在实例化 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) 上它不工作。这post对我帮助不大,因为我还没有找到任何线索,我必须向哪个目录授予写权限。

我发现,以下代码也适用于 Linux 机器:

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

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

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

提前致谢!

最佳答案

您好,问题出在受写入权限保护的文件系统上。 实际上在你的堆栈跟踪中你有:

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

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

如果对您有帮助,请查看我对另一篇文章的回答。

链接 here

关于linux - 在 Linux 系统上记录速度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7793002/

相关文章:

logging - 扭曲。如何为每个请求在日志中写入唯一的前缀

django - Gunicorn Django 并将信息记录到文件中

java - 从 Spring MVC 应用程序发送带有图像的 Velocity 模板化电子邮件

java - 是否有任何基于 java 的模板引擎可以像 apache vm 那样解析动态消息来生成?

foreach - Liferay foreach 向后循环

linux - 使用 cron 时不会发生服务重启

python - 普通用户帐户和 root 之间有什么东西吗?

linux - GDB 警告 : Loadable section not found in added symbol-file system-supplied DSO at 0x7ffff7ffd000

linux - 查找linux内核中的CPU数量

c# - EnterpriseLibrary 记录器错误 : Object synchronization method was called from an unsynchronized block of code