应用无法启动,并且不报错的总结log4j的问题

应用启动不起来,并且不报错。没有任何征兆与线索。经过排查,是log4j的问题,log4j配置如下。

 
       
log4j .rootLogger = INFO,console,logstash
log4j .logger .com .atc=INFO
log4j .appender .console=org .apache .log4j .ConsoleAppender
log4j .appender .console .target=System.out
log4j .appender .console .layout=org .apache .log4j .PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p [%c:%L] - %m%n
log4j .appender .f = org .apache .log4j .DailyRollingFileAppender
log4j .appender .f .File = /data/logs/startup/startup.log
log4j .appender .f .Append = true
log4j .appender .f .layout = org .apache .log4j .PatternLayout
log4j.appender.f.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS} %p [%c:%L] - %m%n
log4j .appender .logstash=org .apache .log4j .net .SocketAppender
log4j .appender .logstash .Port=${port}
log4j .appender .logstash .RemoteHost=${host}
log4j .appender .logstash .layout=org .apache .log4j .PatternLayout
log4j.appender.logstash.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%- 5p] [%c:%L] %m%n
log4j .appender .logstash .ReconnectionDelay= 10000

改成以下就解决了问题:

 
       
log4j .rootLogger = INFO,console,f
log4j .appender .console=org .apache .log4j .ConsoleAppender
log4j .appender .console .target=System.out
log4j .appender .console .layout=org .apache .log4j .PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p [%c:%L] - %m%n
log4j .appender .f = org .apache .log4j .DailyRollingFileAppender
log4j .appender .f .File = /home/root1/logs/startup/startup.log
log4j .appender .f .Append = true
log4j .appender .f .layout = org .apache .log4j .PatternLayout
log4j.appender.f.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss,SSS} %p [%c:%L] - %m%n
log4j .logger .com .atc .daizhang .dao .TaskMasterMapper=INFO
log4j .logger .com .atc .daizhang .dao .TaskBatchMapper=INFO
log4j .logger .com .atc=INFO

没错,把logstash这段去掉就可以了。

分析原因,是logstash所在机器耗尽,导致ELK挂掉,进而导致本篇问题的发生。

P.S.

log4j不建议大家使用,N年不更新了,建议使用logback、log4j2。因为项目的遗留问题,不得不使用log4j。

你可能感兴趣的:(SpringCloud)