From 2760703484f9b12f8c21c395915f9780b1ae7e9e Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 8 Dec 2020 16:19:34 +0100 Subject: ConfigurationFtpService: reduce ftp lib log verbosity The default logging settings of the Apache Mina FtpServer library quickly fill-up the logs at the INFO level. This sets the level to WARN for this library. --- .../tincapp/service/ConfigurationFtpService.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/src/main') diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt index c562768..2ea4a16 100644 --- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt @@ -22,6 +22,8 @@ import android.app.Service import android.content.Intent import android.os.IBinder import androidx.databinding.ObservableBoolean +import ch.qos.logback.classic.Level +import ch.qos.logback.classic.Logger import org.apache.ftpserver.FtpServer import org.apache.ftpserver.FtpServerFactory import org.apache.ftpserver.ftplet.* @@ -42,6 +44,11 @@ import java.io.IOException */ class ConfigurationFtpService : Service() { companion object { + // Apache Mina FtpServer's INFO log level is actually VERBOSE. + // The object holds static references to those loggers so that they stay around. + @Suppress("unused") + private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN) + const val FTP_PORT = 65521 // tinc port `concat` FTP port const val FTP_USERNAME = "tincapp" val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! @@ -125,4 +132,19 @@ class ConfigurationFtpService : Service() { override fun authorize(request: AuthorizationRequest?): AuthorizationRequest? = authorities.filter { it.canAuthorize(request) }.fold(request) { req, auth -> auth.authorize(req) } } + + /** + * This registers package loggers filtering the output of the Mina FtpServer. + * The object holds static references to those loggers so that they stay around. + */ + private class MinaLoggerOverrider(logLevel: Level) { + @Suppress("unused") + private val ftpServerLogger = forceLogLevel("org.apache.ftpserver", logLevel) + + @Suppress("unused") + private val minaLogger = forceLogLevel("org.apache.mina", logLevel) + + private fun forceLogLevel(pkgName: String, logLevel: Level) = + (LoggerFactory.getLogger(pkgName) as Logger).apply { level = logLevel } + } } -- cgit v1.2.3