RequestLog in Jetty 12 without logback-access

RequestLog in Jetty 12 without logback-access
Photo by Stephen yu / Unsplash

Because logback-access is not easy to see through in configuration at the moment and so far it seems impossible to use AsyncAppender with access-log (at least without creating custom classes), I've found a way to get this logging without logback-access.
Jetty 12 provides the logging-logback module with core and classic and with little configuration you get the RequestLog to logback.

Modify the existing <JETTY_HOME>/modules/logging/logback/resources/logback.xml :

<configuration>

  <!-- <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> -->
  <!-- Suppress internal Logback status messages -->
  <statusListener class="ch.qos.logback.core.status.NopStatusListener" />

  <!-- Console appender -->
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <!-- Async wrapper for performance -->
  <appender name="ASYNC_CONSOLE" class="ch.qos.logback.classic.AsyncAppender">
    <queueSize>512</queueSize>
    <discardingThreshold>75</discardingThreshold>
    <appender-ref ref="CONSOLE" />
  </appender>

  <!-- Request appender -->
  <appender name="REQUEST" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%msg%n</pattern>
    </encoder>
  </appender>

  <!-- Async wrapper for performance -->
  <appender name="ASYNC_REQUEST" class="ch.qos.logback.classic.AsyncAppender">
    <queueSize>512</queueSize>
    <discardingThreshold>75</discardingThreshold>
    <appender-ref ref="REQUEST" />
  </appender>

  <!-- org.eclipse.jetty.server.Slf4jRequestLogWriter in jetty-logback-access.xml -->
  <logger name="org.eclipse.jetty.server.RequestLog" level="INFO" additivity="false">
    <appender-ref ref="ASYNC_REQUEST" />
  </logger>

  <!-- Root logger -->
  <root level="INFO">
    <appender-ref ref="ASYNC_CONSOLE" />
  </root>

</configuration>

Create <JETTY_HOME>/modules/logging/jetty-logback-access.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Set name="requestLog">
    <New class="org.eclipse.jetty.server.CustomRequestLog">
      <Arg>
        <New class="org.eclipse.jetty.server.Slf4jRequestLogWriter" />
      </Arg>
      <Arg>%{client}a - %u %t "%r" %s %{CLF}I ib %{CLF}O ob %{ms}T ms "%{Referer}i" "%{User-Agent}i" sess=%{session}i</Arg>
    </New>
  </Set>
</Configure>

Create a module <JETTY_HOME>/modules/logging-logback-access.mod:

# DO NOT EDIT THIS FILE - See: https://jetty.org/docs/

[description]
Enables logback request log.

[tags]
requestlog
logging
logback

[depends]
logging-logback

[provides]
requestlog

[xml]
modules/logging/jetty-logback-access.xml

[license]
Logback: the reliable, generic, fast and flexible logging framework.
Copyright (C) 1999-2012, QOS.ch. All rights reserved.

This program and the accompanying materials are dual-licensed under
either:

    the terms of the Eclipse Public License v1.0
    as published by the Eclipse Foundation:
    http://www.eclipse.org/legal/epl-v10.html

or (per the licensee's choosing) under

    the terms of the GNU Lesser General Public License version 2.1
    as published by the Free Software Foundation:
    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html

Now run your

java -Djetty.base=<JETTY_BASE> -jar <JETTY_HOME>/start.jar --add-module=logging-logback,logging-logback-access

and you should have jetty-, app- and request-log on stdout/console.

Of course you don't need to modify the existing logback.xml template, but could also modify the file in <JETTY_BASE>/resources/logback.xml after adding the logging-logback module to it.