Skip to content

Logging (SLF4J)

When you setup a JDA project you should also setup a logging implementation for SLF4J. This is only necessary if you get a warning like this on startup:

SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See for further details.

I recommend logback-classic as it is my goto implementation. First add logback to your dependencies:

dependencies {

Configure Logback

The logback configuration needs to be in your resources directory. This is src/main/resources in all standard Gradle and Maven projects. Add the following configuration into src/main/resources/logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n</pattern>

    <root level="info">
        <appender-ref ref="STDOUT" />

You can read up on how this configuration works in the logback manual.

How to enable debug logs

In the config above, change the level for the root logger to debug:

<root level="debug">

Supported MDC Options

There are a few built-in MDC options used by JDA:

  • jda.shard The shard id and shard total in the format [id / total]. (This is 0-based so with a total of 10 the last shard id [9 / 10])
  • The shard id
  • The shard total

You can further configure other MDC variables for JDA threads with JDABuilder.setContextMap!