diff --git a/LavalinkServer/application.yml.example b/LavalinkServer/application.yml.example index 06393d8ec..b1ba3d02d 100644 --- a/LavalinkServer/application.yml.example +++ b/LavalinkServer/application.yml.example @@ -19,3 +19,13 @@ lavalink: sentryDsn: "" bufferDurationMs: 400 youtubePlaylistLoadLimit: 600 + +logging: + file: + max-history: 30 + max-size: 1GB + path: ./logs/ + + level: + root: INFO + lavalink: INFO diff --git a/LavalinkServer/build.gradle b/LavalinkServer/build.gradle index 2b1904583..9627079be 100644 --- a/LavalinkServer/build.gradle +++ b/LavalinkServer/build.gradle @@ -15,8 +15,8 @@ bootJar { requiresUnpack '**/jda-nas*.jar' //otherwise we get missing classes exceptions } -sourceCompatibility = 9 -targetCompatibility = 9 +sourceCompatibility = 10 +targetCompatibility = 10 bootRun { //compiling tests during bootRun increases the likelyhood of catching broken tests locally instead of on the CI diff --git a/LavalinkServer/docker/Dockerfile b/LavalinkServer/docker/Dockerfile index 04e02e9bb..847be60be 100644 --- a/LavalinkServer/docker/Dockerfile +++ b/LavalinkServer/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:9-jre-slim +FROM openjdk:10-jre-slim WORKDIR /opt/Lavalink diff --git a/LavalinkServer/src/main/java/lavalink/server/Launcher.java b/LavalinkServer/src/main/java/lavalink/server/Launcher.java index aa353ed55..36526f235 100644 --- a/LavalinkServer/src/main/java/lavalink/server/Launcher.java +++ b/LavalinkServer/src/main/java/lavalink/server/Launcher.java @@ -22,11 +22,6 @@ package lavalink.server; -import ch.qos.logback.classic.LoggerContext; -import io.sentry.Sentry; -import io.sentry.SentryClient; -import io.sentry.logback.SentryAppender; -import lavalink.server.config.ServerConfig; import lavalink.server.io.SocketServer; import lavalink.server.util.SimpleLogToSLF4JAdapter; import net.dv8tion.jda.utils.SimpleLog; @@ -37,9 +32,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import java.io.IOException; -import java.util.Properties; - @SpringBootApplication @ComponentScan public class Launcher { @@ -54,7 +46,7 @@ public static void main(String[] args) { sa.run(args); } - public Launcher(ServerConfig serverConfig, SocketServer socketServer) { + public Launcher(SocketServer socketServer) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { log.info("Shutdown hook triggered"); try { @@ -66,40 +58,5 @@ public Launcher(ServerConfig serverConfig, SocketServer socketServer) { SimpleLog.LEVEL = SimpleLog.Level.OFF; SimpleLog.addListener(new SimpleLogToSLF4JAdapter()); - initSentry(serverConfig); - } - - private void initSentry(ServerConfig serverConfig) { - String sentryDsn = serverConfig.getSentryDsn(); - if (sentryDsn == null || sentryDsn.isEmpty()) { - log.info("No sentry dsn found, turning off sentry."); - turnOffSentry(); - return; - } - SentryClient sentryClient = Sentry.init(sentryDsn); - log.info("Set up sentry."); - - // set the git commit hash this was build on as the release - Properties gitProps = new Properties(); - try { - gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties")); - } catch (NullPointerException | IOException e) { - log.error("Failed to load git repo information", e); - } - - String commitHash = gitProps.getProperty("git.commit.id"); - if (commitHash != null && !commitHash.isEmpty()) { - log.info("Setting sentry release to commit hash {}", commitHash); - sentryClient.setRelease(commitHash); - } else { - log.warn("No git commit hash found to set up sentry release"); - } - } - - private void turnOffSentry() { - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); - SentryAppender sentryAppender = (SentryAppender) lc.getLogger(Logger.ROOT_LOGGER_NAME).getAppender("SENTRY"); - Sentry.close(); - sentryAppender.stop(); } } diff --git a/LavalinkServer/src/main/java/lavalink/server/config/SentryConfiguration.java b/LavalinkServer/src/main/java/lavalink/server/config/SentryConfiguration.java new file mode 100644 index 000000000..194f2ea9e --- /dev/null +++ b/LavalinkServer/src/main/java/lavalink/server/config/SentryConfiguration.java @@ -0,0 +1,86 @@ +package lavalink.server.config; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.filter.ThresholdFilter; +import io.sentry.Sentry; +import io.sentry.SentryClient; +import io.sentry.logback.SentryAppender; +import lavalink.server.Launcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; + +import java.io.IOException; +import java.util.Properties; + +/** + * Created by napster on 25.04.18. + */ +@Configuration +public class SentryConfiguration { + + private static final Logger log = LoggerFactory.getLogger(SentryConfiguration.class); + private static final String SENTRY_APPENDER_NAME = "SENTRY"; + + public SentryConfiguration(ServerConfig serverConfig) { + String sentryDsn = serverConfig.getSentryDsn(); + if (sentryDsn != null && !sentryDsn.isEmpty()) { + turnOn(sentryDsn); + } else { + turnOff(); + } + } + + + public void turnOn(String dsn) { + log.info("Turning on sentry"); + SentryClient sentryClient = Sentry.init(dsn); + + // set the git commit hash this was build on as the release + Properties gitProps = new Properties(); + try { + gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties")); + } catch (NullPointerException | IOException e) { + log.error("Failed to load git repo information", e); + } + + String commitHash = gitProps.getProperty("git.commit.id"); + if (commitHash != null && !commitHash.isEmpty()) { + log.info("Setting sentry release to commit hash {}", commitHash); + sentryClient.setRelease(commitHash); + } else { + log.warn("No git commit hash found to set up sentry release"); + } + + getSentryLogbackAppender().start(); + } + + public void turnOff() { + log.warn("Turning off sentry"); + Sentry.close(); + getSentryLogbackAppender().stop(); + } + + //programmatically creates a sentry appender + private static synchronized SentryAppender getSentryLogbackAppender() { + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + ch.qos.logback.classic.Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + + SentryAppender sentryAppender = (SentryAppender) root.getAppender(SENTRY_APPENDER_NAME); + if (sentryAppender == null) { + sentryAppender = new SentryAppender(); + sentryAppender.setName(SENTRY_APPENDER_NAME); + + ThresholdFilter warningsOrAboveFilter = new ThresholdFilter(); + warningsOrAboveFilter.setLevel(Level.WARN.levelStr); + warningsOrAboveFilter.start(); + sentryAppender.addFilter(warningsOrAboveFilter); + + sentryAppender.setContext(loggerContext); + root.addAppender(sentryAppender); + } + return sentryAppender; + } + +} diff --git a/LavalinkServer/src/main/resources/logback.xml b/LavalinkServer/src/main/resources/logback.xml deleted file mode 100644 index 82bce4af5..000000000 --- a/LavalinkServer/src/main/resources/logback.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - INFO - - logs/lavalink.log - - logs/lavalink.%d{yyyyMMdd}.log - 7 - - - [%date{HH:mm:ss}] [ %-5level] [%logger{0}] %msg%n - - - - - logs/debug.log - - DEBUG - - - logs/debug.%d{yyyyMMdd}.log.gz - 5 - - - [%d] [ %-5level] [%thread] %logger{35}: %msg%n - - - - - logs/error.log - - ERROR - - - logs/error.%d{yyyyMMdd}.log - 30 - - - [%date{HH:mm:ss}] [%thread] [%logger{0}] %msg%n - - - - - - INFO - - - [%date{HH:mm:ss}] [ %-5level] [%logger{0}] %msg%n - - - - - - WARN - - - - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index 556128822..3cecb5880 100644 --- a/build.gradle +++ b/build.gradle @@ -67,9 +67,8 @@ ext { moduleName = 'Lavalink-Parent' } -import org.gradle.api.tasks.wrapper.Wrapper.DistributionType - task wrapper(type: Wrapper) { - gradleVersion = '4.6' - distributionType = DistributionType.ALL + gradleVersion = '4.7' + //noinspection UnnecessaryQualifiedReference + distributionType = Wrapper.DistributionType.ALL } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f6b961fd5..91ca28c8b 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a4163a4f..e6a30918e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists