问题
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