日志未保存在文件中

时间:2019-02-13 05:08:05

标签: spring-boot log4j

日志未保存在文件中,而是显示在控制台上。以下是log4j属性:

name=PropertiesConfig
property.filename = logs
appenders = console, file

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/propertieslogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

loggers=file
logger.file.name=transfer
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE

rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

logger.file.additivity=false

1 个答案:

答案 0 :(得分:0)

我可以看到很多不必要的字段。在.properties文件中添加以下内容,它应该可以工作(根据您的要求更改值)。

log4j.rootLogger=INFO, stdout, R, DEBUG
log4j.logger.org.apache.http=ERROR
log4j.logger.org.apache.http.wire=ERROR

#Logging to stdout to catalina.out
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern={"@timestamp": "%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}", "type":"lh_idm", "@message": "%m", "@fields": {"priority": "%p", "logger_name": "%c"}}%n


log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.maxFileSize=20MB
log4j.appender.R.maxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern={"@timestamp": "%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}", "type":"lh_idm", "@message": "%m", "@fields": {"priority": "%p", "logger_name": "%c"}}%n
log4j.appender.R.File=${catalina.base}/logs/idme.log