Is the default file appended of Logback:
ch.qos.logback.core.FileAppender
synchronous or asynchronous? It seems to be synchronous as the logs are being shown as part of same thread.
Is the default file appended of Logback:
ch.qos.logback.core.FileAppender
synchronous or asynchronous? It seems to be synchronous as the logs are being shown as part of same thread.
Yes, it's synchronous by default. You can see a config example on how to make it asynchronous in the documentation.
This way, you can make any Appender
asynchronous much easier (by simply wrapping it in an AsyncAppender
) than if all Appender
implementations would have to manage the asynchronicity on their own.
Most appenders are synchronous, for example, RollingFileAppender
. To enable async logging, you must wrap an appender with AsyncAppender
to create an async appender based on the sync one, and it could be done easily in XML like below.
<appender name="ASYNC-VERSION-APPENDER" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="DEFAULT-APPENDER"/>
</appender>
<logger name="ASYNC-LOGGER" level="INFO" additivity="false">
<appender-ref ref="ASYNC-VERSION-APPENDER"/>
</logger>
See this: here we are wrapping MyFileAppender
appender with AsyncAppender
to make an async version of MyFileAppender
<appender name="MyFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
...
</appender>
<!-- this one wraps `MyFileAppender` appender with AsyncAppender to make an async version of MyFileAppender->
<appender name="ASYNC-FileAppender" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>512</queueSize>
<appender-ref ref="MyFileAppender"/>
</appender>
<root level="${logging.level.root}">
<appender-ref ref="ASYNC-FileAppender"/>
</root>
© 2022 - 2024 — McMap. All rights reserved.