How to set filePermissions in log4j.properties file

狂风中的少年 提交于 2021-02-11 12:36:30

问题


I am using slf4j-log4j12 latest version 1.7.25. We are using kibana to view logs, but the Kibana fails to read logs from tomcat. I need to set filePermissions to read files from tomcat in log4j.properties file.

filePermissions="rw-r-----"

My log4j.properties file,

# Put log messages in rolling log file
log4j.rootLogger=info, file
log4j.logger.com.sample=debug
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=logs/MyService.log
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c{4} %M:%L - %m%n

Kindly provide your thoughts on this


回答1:


If I get your question right. Regarding official docs:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" name="MyApp" packages="">
  <Properties>
    <Property name="baseDir">logs</Property>
  </Properties>
  <Appenders>
    <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
                 filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyyMMdd}.log.gz"
                 filePermissions="rw-------">
      <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
      <CronTriggeringPolicy schedule="0 0 0 * * ?"/>
      <DefaultRolloverStrategy stopCustomActionsOnError="true">
        <PosixViewAttribute basePath="${baseDir}/$${date:yyyy-MM}" filePermissions="r--r--r--">
            <IfFileName glob="*.gz" />
        </PosixViewAttribute>
      </DefaultRolloverStrategy>
    </RollingFile>
  </Appenders>

  <Loggers>
    <Root level="error">
      <AppenderRef ref="RollingFile"/>
    </Root>
  </Loggers>

</Configuration>

Link: https://logging.apache.org/log4j/2.x/manual/appenders.html

It could be log4j.appender.file.filePermissions=rw------- but it should be tested! The idea is that this attribute is configured as others.



来源:https://stackoverflow.com/questions/54343785/how-to-set-filepermissions-in-log4j-properties-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!