[
https://issues.apache.org/jira/browse/LOG4J2-3549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576631#comment-17576631
]
yimiluo commented on LOG4J2-3549:
---------------------------------
I tried setting immediateFlush to false, but the service is still blocked, the
following is the configuration of my service.
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off" monitorInterval="1800" shutdownHook="disable">
<properties>
<property name="LOG_HOME">logs</property>
<property name="LOG_PATTERN">[%d{yyyy-MM-dd
HH:mm:ss:SSS}]|%traceId|%t|[%level]|%logger{1}|%msg%n
</property>
</properties>
<appenders>
<Console name="stdout" target="SYSTEM_OUT">
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
</Console>
<RollingRandomAccessFile name="trace-file" immediateFlush="false"
fileName="${LOG_HOME}/trace.log"
filePattern="${LOG_HOME}/trace.%d{yyyy-MM-dd}-%i.log.gz">
<Filters>
<ThresholdFilter level="debug" onMatch="DENY" onMismatch="ACCEPT"/>
<ThresholdFilter level="trace" onMatch="NEUTRAL" onMismatch="DENY"/>
</Filters>
<PatternLayout
pattern="${LOG_PATTERN}" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="100">
<Delete basePath="${LOG_HOME}">
<IfFileName glob="*.*.log.gz"/>
<IfLastModified age="1d"/>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="error-file" immediateFlush="false"
fileName="${LOG_HOME}/error.log"
filePattern="${LOG_HOME}/error.%d{yyyy-MM-dd}-%i.log.gz">
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="debug-file" immediateFlush="false"
fileName="${LOG_HOME}/debug.log"
filePattern="${LOG_HOME}/debug.%d{yyyy-MM-dd}-%i.log.gz">
<Filters>
<ThresholdFilter level="debug" onMatch="NEUTRAL" onMismatch="DENY"/>
<ThresholdFilter level="info" onMatch="DENY" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="warn-file" immediateFlush="false"
fileName="${LOG_HOME}/warn.log"
filePattern="${LOG_HOME}/warn.%d{yyyy-MM-dd}-%i.log.gz">
<Filters>
<ThresholdFilter level="warn" onMatch="NEUTRAL" onMismatch="DENY"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="info-file" immediateFlush="false"
fileName="${LOG_HOME}/info.log"
filePattern="${LOG_HOME}/info.%d{yyyy-MM-dd}-%i.log.gz">
<Filters>
<ThresholdFilter level="info" onMatch="NEUTRAL" onMismatch="DENY"/>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout
pattern="${LOG_PATTERN}" charset="UTF-8"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="100">
<Delete basePath="${LOG_HOME}">
<IfFileName glob="*.*.log.gz"/>
<IfLastModified age="1d"/>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</appenders>
<loggers>
<root level="trace">
<appender-ref ref="info-file"/>
<appender-ref ref="debug-file"/>
<appender-ref ref="error-file"/>
<appender-ref ref="warn-file"/>
<appender-ref ref="trace-file"/>
<appender-ref ref="stdout"/>
</root>
</loggers>
</configuration>
{code}
> The printed thread blocked
> --------------------------
>
> Key: LOG4J2-3549
> URL: https://issues.apache.org/jira/browse/LOG4J2-3549
> Project: Log4j 2
> Issue Type: Bug
> Components: Log4j 1.2 bridge
> Affects Versions: 2.17.2
> Reporter: yimiluo
> Priority: Minor
> Attachments: image-2022-07-08-20-20-11-818.png
>
>
> When we were printing the log, the printed thread was blocked, causing the
> service to go down. The following is the exception information:
> !image-2022-07-08-20-20-11-818.png|width=895,height=537!
> {code:java}
> [arthas@1]$ thread -b
> "http-nio-8080-exec-5" Id=97 RUNNABLE (in native)
> at [email protected]/java.io.FileOutputStream.writeBytes(Native Method)
> at
> [email protected]/java.io.FileOutputStream.write(FileOutputStream.java:354)
> at
> [email protected]/java.io.BufferedOutputStream.write(BufferedOutputStream.java:123)
> - locked java.io.BufferedOutputStream@ea9396a
> at [email protected]/java.io.PrintStream.write(PrintStream.java:559)
> - locked java.io.PrintStream@3ff1e46c
> at
> org.apache.logging.log4j.core.util.CloseShieldOutputStream.write(CloseShieldOutputStream.java:53)
> at
> org.apache.logging.log4j.core.appender.OutputStreamManager.writeToDestination(OutputStreamManager.java:250)
> at
> org.apache.logging.log4j.core.appender.OutputStreamManager.flushBuffer(OutputStreamManager.java:283)
> - locked
> org.apache.logging.log4j.core.appender.OutputStreamManager@7ba4158c <---- but
> blocks 236 other threads!
> at
> org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:294)
> - locked
> org.apache.logging.log4j.core.appender.OutputStreamManager@7ba4158c <---- but
> blocks 236 other threads!
> at
> org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:199)
> at
> org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:190)
> at
> org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:181)
> at
> org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:161)
> at
> org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:134)
> at
> org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
> at
> org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
> at
> org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:542)
> at
> org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:500)
> at
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:483)
> at
> org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:417)
> at
> org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
> at org.apache.logging.log4j.core.Logger.log(Logger.java:161)
> at
> org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
> at
> org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
> at
> org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
> at
> org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2028)
> at
> org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1891)
> at org.apache.logging.slf4j.Log4jLogger.info(Log4jLogger.java:194) {code}
>
> I don't know what the solution is now. I would be very grateful if you could
> reply.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)