Java Apache Tomcat 日志记录默认权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20552756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:45:36  来源:igfitidea点击:

Apache Tomcat logging default permissions

javaapachetomcatlogging

提问by javasauce

I'm wondering if there's any way to set default file permissions of the logs created using Tomcat's logging.properties files? My logging.properties file looks like this:

我想知道是否有任何方法可以设置使用 Tomcat 的 logging.properties 文件创建的日志的默认文件权限?我的 logging.properties 文件如下所示:

handlers = java.util.Logging.FileHandler

java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.pattern = /var/lib/<TOMCAT INSTANCE>/logs/system.log
java.util.logging.FileHandler.limit = 2097152
java.util.logging.FileHandler.count = 50
java.util.logging.FileHandler.formatter = java.util.Logging.SimpleFormatter

I want all logs that are created to have file permissions of 640, however after reading some documentation about FileHandler and other alternatives, I'm not sure this is possible.

我希望所有创建的日志都具有 640 的文件权限,但是在阅读了有关 FileHandler 和其他替代方案的一些文档后,我不确定这是否可行。

Any help/direction would be greatly appreciated!

任何帮助/方向将不胜感激!

Thanks for your time.

谢谢你的时间。

回答by pksiazek

The only way is to change umask for owner of Tomcat process (best place from that would be Tomcat startup script).

唯一的方法是更改​​ Tomcat 进程所有者的 umask(最好的地方是 Tomcat 启动脚本)。

But beware that this will change permissions of ALL files created by Tomcat.

但请注意,这将更改 Tomcat 创建的所有文件的权限。

回答by Laura

I spent a long time searching for this today, so I'm posting my solution to this old ticket. I am working from a Linux install, which I believe is what the original poster was also using.

我今天花了很长时间搜索这个,所以我将我的解决方案发布到这张旧票上。我正在使用 Linux 安装,我相信原始海报也在使用它。

In Tomcat 8.5, this is controlled with the environment variable UMASK. If this variable is not set when Tomcat is started, then Tomcat will set the umask to 0027, so that files have the permissions (rw-r-----). You can see this logic for this in Tomcat's bin/catalina.sh file.

在 Tomcat 8.5 中,这是由环境变量 UMASK 控制的。如果Tomcat启动时没有设置这个变量,那么Tomcat会设置umask为0027,这样文件才有权限(rw-r-----)。您可以在 Tomcat 的 bin/catalina.sh 文件中看到此逻辑。

This solution is different from pksiazek's solution because it does not involve editing any of Tomcat's scripts, in case that is a concern. It is the same as pksiazek's solution in that it will affect all files created by Tomcat, not just log files.

此解决方案与 pksiazek 的解决方案不同,因为它不涉及编辑任何 Tomcat 的脚本,以防万一。它与pksiazek的解决方案相同,它会影响Tomcat创建的所有文件,而不仅仅是日志文件。

For anyone not as familiar with how umask values map to file permissions, you may find a Umask calculator helpful. Here's one: http://www.webune.com/forums/umask-calculator.html

对于不熟悉 umask 值如何映射到文件权限的任何人,您可能会发现 Umask 计算器很有帮助。这是一个:http: //www.webune.com/forums/umask-calculator.html