diff options
author | pacien | 2020-12-08 16:19:34 +0100 |
---|---|---|
committer | pacien | 2020-12-08 16:19:34 +0100 |
commit | 2760703484f9b12f8c21c395915f9780b1ae7e9e (patch) | |
tree | ae037a07826839bcc69e2ea1a9a753efaff1c05d /app | |
parent | 20ecd9840f1e237dba79674b71e49b43b074902e (diff) | |
download | tincapp-2760703484f9b12f8c21c395915f9780b1ae7e9e.tar.gz |
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.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt | 22 |
1 files changed, 22 insertions, 0 deletions
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 | |||
22 | import android.content.Intent | 22 | import android.content.Intent |
23 | import android.os.IBinder | 23 | import android.os.IBinder |
24 | import androidx.databinding.ObservableBoolean | 24 | import androidx.databinding.ObservableBoolean |
25 | import ch.qos.logback.classic.Level | ||
26 | import ch.qos.logback.classic.Logger | ||
25 | import org.apache.ftpserver.FtpServer | 27 | import org.apache.ftpserver.FtpServer |
26 | import org.apache.ftpserver.FtpServerFactory | 28 | import org.apache.ftpserver.FtpServerFactory |
27 | import org.apache.ftpserver.ftplet.* | 29 | import org.apache.ftpserver.ftplet.* |
@@ -42,6 +44,11 @@ import java.io.IOException | |||
42 | */ | 44 | */ |
43 | class ConfigurationFtpService : Service() { | 45 | class ConfigurationFtpService : Service() { |
44 | companion object { | 46 | companion object { |
47 | // Apache Mina FtpServer's INFO log level is actually VERBOSE. | ||
48 | // The object holds static references to those loggers so that they stay around. | ||
49 | @Suppress("unused") | ||
50 | private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN) | ||
51 | |||
45 | const val FTP_PORT = 65521 // tinc port `concat` FTP port | 52 | const val FTP_PORT = 65521 // tinc port `concat` FTP port |
46 | const val FTP_USERNAME = "tincapp" | 53 | const val FTP_USERNAME = "tincapp" |
47 | val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! | 54 | val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! |
@@ -125,4 +132,19 @@ class ConfigurationFtpService : Service() { | |||
125 | override fun authorize(request: AuthorizationRequest?): AuthorizationRequest? = | 132 | override fun authorize(request: AuthorizationRequest?): AuthorizationRequest? = |
126 | authorities.filter { it.canAuthorize(request) }.fold(request) { req, auth -> auth.authorize(req) } | 133 | authorities.filter { it.canAuthorize(request) }.fold(request) { req, auth -> auth.authorize(req) } |
127 | } | 134 | } |
135 | |||
136 | /** | ||
137 | * This registers package loggers filtering the output of the Mina FtpServer. | ||
138 | * The object holds static references to those loggers so that they stay around. | ||
139 | */ | ||
140 | private class MinaLoggerOverrider(logLevel: Level) { | ||
141 | @Suppress("unused") | ||
142 | private val ftpServerLogger = forceLogLevel("org.apache.ftpserver", logLevel) | ||
143 | |||
144 | @Suppress("unused") | ||
145 | private val minaLogger = forceLogLevel("org.apache.mina", logLevel) | ||
146 | |||
147 | private fun forceLogLevel(pkgName: String, logLevel: Level) = | ||
148 | (LoggerFactory.getLogger(pkgName) as Logger).apply { level = logLevel } | ||
149 | } | ||
128 | } | 150 | } |