简体   繁体   English

如何以编程方式设置log4j日志文件的权限?

[英]How to set permission for log file of log4j programmatically?

If my application is run by root user, creating log file by root. 如果我的应用程序是由root用户运行的,请按root创建日志文件。 So, if the app is run by another users, display 'permission denied'. 因此,如果该应用由其他用户运行,则显示“权限被拒绝”。

There are the logs in /opt/myapp/logs/ . /opt/myapp/logs/

I want to set permission for log file of log4j programmatically (May be using log4j configuration) (All user should write the log file. To permit as chmod 766 ). 我想以编程方式设置log4j日志文件的权限(可能正在使用log4j配置)(所有用户都应写入日志文件。允许为chmod 766 )。 Is it possible? 可能吗?

Writing logs to single folder will require to manually set log file name and change log folder permissions. 将日志写入单个文件夹将需要手动设置日志文件名并更改日志文件夹权限。

If you need to run your application from many users you will likely should use user home (or sub folder) to write logs. 如果您需要从许多用户处运行应用程序,则可能应该使用用户主目录(或子文件夹)来编写日志。

According to the Filesystem Hierarchy Standard, logs must be put in /var/log . 根据文件系统层次结构标准,必须将日志放在/var/log You can avoid clutter this folder by creating a /var/log/myapp folder, where you'll put your logs. 您可以通过创建/var/log/myapp文件夹来避免混乱该文件夹,在该文件夹中放置日志。 Ensure the folder and its contents are chmod 666, or better, 766. 确保文件夹及其内容为chmod 666或更好的766。

This is the standard used by Apache, for example. 例如,这是Apache使用的标准。

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

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