In my DW app I am trying to make the logging to the file and console asynchronous. I found that I can use the AsyncAppender, but is that already configured in DropWizard or do I need to enable it, if so how do I configure the logger to use the AsyncAppender
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
AsyncAppender fileAppender = (AsyncAppender) root.getAppender("async-file-appender");
My config.yaml is looks like this
server:
minThreads: 512
type: default
supportedCarParcFile: /opt/foo/my_app/config/my-app.json
logging:
appenders:
-
threshold: INFO
type: console
-
archivedFileCount: 7
archivedLogFilenamePattern: /opt/foo/my_app/logs/my-app-%d.log.gz
currentLogFilename: /opt/foo/my_app/logs/my-app.log
threshold: INFO
timeZone: CST
type: file
-
archivedFileCount: 7
archivedLogFilenamePattern: /opt/foo/my_app/logs/my-app_error-%d.log.gz
currentLogFilename: /opt/foo/my_app/logs/my-app_error.log
threshold: ERROR
timeZone: CST
type: file
loggers:
metrics:
additive: true
appenders:
-
archivedFileCount: 10
archivedLogFilenamePattern: /opt/foo/my_app/logs/metrics-%d.log.gz
currentLogFilename: /opt/foo/my_app/logs/metrics.log
type: file
level: INFO
I am using DropWizard 1.0.5.
The
DefaultLoggingFactoryin dropwizard is used by default for logging purposes.Which as you can see here makes use of the
AsyncLoggingEventAppenderFactoryusing theAsyncAppenderBaseto build the appenders. The documentation ofch.qos.logback.core.AsyncAppenderBasestates that:Now to your question, but is that already configured in DropWizard or do I need to enable it?
I would say, you don't need to enable it explicitly to configure async appending of the logs. The
AsyncLoggingEventAppenderFactoryshall take care of it.