Fra*_*anz 6 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)
Run Code Online (Sandbox Code Playgroud)
这是我的代码片段:
VelocityEngine ve = new VelocityEngine();
ve.evaluate(context, writer, "org.apache.velocity.runtime.log.NullLogChute", this.templateString);
Run Code Online (Sandbox Code Playgroud)
起初我的代码看起来像这样:
runtimeServices = RuntimeSingleton.getRuntimeServices();
node = runtimeServices.parse(reader, templateName);
Run Code Online (Sandbox Code Playgroud)
在我的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);
Run Code Online (Sandbox Code Playgroud)
这不是一个非常好的解决方案,因为我无法确定,如果我对我的真实上下文路径有写权限.最好的是,只关闭Velocity的记录.
我必须设置哪些不同的日志配置?是NullLogChute
不工作还是我用它不合适?
提前致谢!
小智 -1
您好,问题出在受写权限保护的 fs 上。事实上,在你的堆栈跟踪中你有:
java.io.FileNotFoundException: velocity.log (Permission denied)
Run Code Online (Sandbox Code Playgroud)
因此,决定将速度日志写入何处是一件好事。你说得好,你不知道在生产中是否可以写入特定路径。因此,最好将该路径放在系统管理员可以根据需要修改的属性文件中。
所以请检查我对另一篇文章的回答是否可以帮助您。
链接在这里