Logging
Add a logger with the following dependencies:
<dependencies>
...
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>SLF4J_VERSION</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>LOGBACK_VERSION</version>
</dependency>
</dependencies>
repositories {
...
mavenCentral()
}
dependencies {
...
implementation("org.slf4j:slf4j-api:SLF4J_VERSION")
implementation("ch.qos.logback:logback-classic:LOGBACK_VERSION")
}
Here are the logback configs I recommend using:
I would recommend putting it in your project, in a folder containing your config files, and load it as such:
Danger
Just like any sensitive data, make sure to add the folder to your .gitignore, as it will contain much more than just the logback config.
However, you can provide a template for contributors/other users.
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, PATH_TO_LOGBACK.absolutePathString())
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, PATH_TO_LOGBACK.toAbsolutePath().toString());
logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true"> <!-- Reloads every minute -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %boldCyan(%-26.-26thread) %boldYellow(%-20.-20logger{0}) %highlight(%-6level) %msg%n%throwable</pattern>
</encoder>
</appender>
<!-- JDA -->
<logger name="net.dv8tion.jda" level="info"/>
<!-- HikariCP -->
<logger name="com.zaxxer.hikari" level="info"/>
<!-- Flyway -->
<logger name="org.flywaydb" level="warn"/>
<!-- BotCommands -->
<logger name="io.github.freya022.botcommands" level="debug"/>
<!-- Other logs -->
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
I would recommend putting it in a folder next to the bot's JAR, and load it as such:
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, PATH_TO_LOGBACK.absolutePathString())
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, PATH_TO_LOGBACK.toAbsolutePath().toString());
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true"> <!-- Reloads every minute -->
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %boldCyan(%-26.-26thread) %boldYellow(%-20.-20logger{0}) %highlight(%-6level) %msg%n%throwable</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/latest.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logs/logs-%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 90 days worth of history capped at 3GB total size -->
<maxHistory>90</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-26.-26thread %-36.-36class{36} #%-24.-24method{24} L%-5.-5line %-20.-20logger{0} %-6level %msg%n%throwable</pattern>
</encoder>
</appender>
<!-- JDA -->
<logger name="net.dv8tion.jda" level="info"/>
<!-- HikariCP -->
<logger name="com.zaxxer.hikari" level="info"/>
<!-- Flyway -->
<logger name="org.flywaydb" level="info"/>
<!-- BotCommands -->
<logger name="io.github.freya022.botcommands" level="debug"/>
<!-- Other logs -->
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>