Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions on log files created by log4j RollingFileAppender

Tags:

How are the permissions for files created by RollingFileAppender determined?

I recently changed a daemon process I have to be run as a non-root user and the files are now being created with permissions of 0600 (only readable by the owner), but I would like them to be readable by all or at least members of an admin group (0644 or 0640). Files created by my tomcat apps are always 0644 (readable by all).

I don't know if I inadvertently changed something else or if it is something to do with permissions of that user. I made the parent directory 0777 as a test and it didn't seem to help (it was 0755). Obviously not a big deal since I can sudo to look at them, but rather annoying and it will be a problem if I have to have a customer copy them for me.

Environment is Ubuntu 10.04LTS using jsvc/commons-daemon to run the daemon. In case it matters here is the basics on my log4j config:

<!DOCTYPE log4j:configuration SYSTEM 'log4j.dtd'> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">  <appender name="StdOutAppender" class="org.apache.log4j.ConsoleAppender">     <!-- only send error / fatal messages to console (catalina.out) -->     <param name="threshold" value="${log4j.StdOutAppender.threshold}" />     <layout class="org.apache.log4j.PatternLayout">         <param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />         <!--%d{dd-MMM-yyyy HH:mm:ss.SSS} [%5p] %c{2}.%M [line:%L]: %m%n-->     </layout> </appender>  <appender name="TimeBasedRollingFileAppender" class="org.apache.log4j.rolling.RollingFileAppender">     <param name="append" value="true" />     <param name="encoding" value="UTF-8" />     <param name="threshold" value="${log4j.TimeBasedRollingFileAppender.threshold}" />     <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">         <param name="FileNamePattern" value="${cloud.daemon.log4j.file.config.path}.%d.gz" />     </rollingPolicy>     <layout class="org.apache.log4j.PatternLayout">         <param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />         <!--%d{dd-MMM-yyyy HH:mm:ss.SSS} [%5p] %c{2}.%M [line:%L]: %m%n-->     </layout> </appender> .... 
like image 231
Ken Waln Avatar asked Oct 25 '11 17:10

Ken Waln


People also ask

What is RollingFileAppender in log4j?

Log4j2 RollingFileAppender is an OutputStreamAppender that writes log messages to files, following a configured triggering policy about when a rollover (backup) should occur. It also has a configured rollover strategy about how to rollover the file.

What are Appenders and loggers in log4j?

Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.

Where should log4j properties be placed?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

Which log4j component is responsible for logging messages?

log4j has three main components: loggers: Responsible for capturing logging information. appenders: Responsible for publishing logging information to various preferred destinations. layouts: Responsible for formatting logging information in different styles.


1 Answers

File permissions are determined by the user's umask - there's not a way to change it in log4j itself.

You probably want to set the user's umask to 0117

$ umask -S 0117 u=rw,g=rw,o= 
like image 60
Brian Roach Avatar answered Nov 08 '22 07:11

Brian Roach