LoggerUtils -> kt
This commit is contained in:
parent
aa7de3b8c4
commit
e1c7963c98
4 changed files with 45 additions and 48 deletions
|
@ -1,25 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.maintenance;
|
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ch.qos.logback.classic.LoggerContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides serveral methods for log-handling (eg. sending logs as emails).
|
|
||||||
*/
|
|
||||||
public class LoggerUtils {
|
|
||||||
|
|
||||||
public static String SUFFIX = ".log.zip";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the directory, in which the logs are stored on the system. This is configured in the
|
|
||||||
* logback.xml file.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getLogDirectory() {
|
|
||||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
|
||||||
return lc.getProperty("EXT_FILES_DIR");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.maintenance
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.LoggerContext
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides several methods for log-handling (eg. sending logs as emails).
|
||||||
|
*/
|
||||||
|
object LoggerUtils {
|
||||||
|
|
||||||
|
var SUFFIX = ".log.zip"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the directory, in which the logs are stored on the system. This is configured in the
|
||||||
|
* logback.xml file.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
val logDirectory: String
|
||||||
|
get() {
|
||||||
|
val lc = LoggerFactory.getILoggerFactory() as LoggerContext
|
||||||
|
return lc.getProperty("EXT_FILES_DIR")
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,7 +51,7 @@ class MaintenancePlugin @Inject constructor(
|
||||||
fun sendLogs() {
|
fun sendLogs() {
|
||||||
val recipient = sp.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org")
|
val recipient = sp.getString(R.string.key_maintenance_logs_email, "logs@androidaps.org")
|
||||||
val amount = sp.getInt(R.string.key_maintenance_logs_amount, 2)
|
val amount = sp.getInt(R.string.key_maintenance_logs_amount, 2)
|
||||||
val logDirectory = LoggerUtils.getLogDirectory()
|
val logDirectory = LoggerUtils.logDirectory
|
||||||
val logs = getLogFiles(logDirectory, amount)
|
val logs = getLogFiles(logDirectory, amount)
|
||||||
val zipDir = context.getExternalFilesDir("exports")
|
val zipDir = context.getExternalFilesDir("exports")
|
||||||
val zipFile = File(zipDir, constructName())
|
val zipFile = File(zipDir, constructName())
|
||||||
|
@ -66,8 +66,7 @@ class MaintenancePlugin @Inject constructor(
|
||||||
//todo replace this with a call on startup of the application, specifically to remove
|
//todo replace this with a call on startup of the application, specifically to remove
|
||||||
// unnecessary garbage from the log exports
|
// unnecessary garbage from the log exports
|
||||||
fun deleteLogs() {
|
fun deleteLogs() {
|
||||||
LoggerUtils.getLogDirectory()?.let { logDirectory ->
|
val logDir = File(LoggerUtils.logDirectory)
|
||||||
val logDir = File(logDirectory)
|
|
||||||
val files = logDir.listFiles { _: File?, name: String ->
|
val files = logDir.listFiles { _: File?, name: String ->
|
||||||
(name.startsWith("AndroidAPS") && name.endsWith(".zip"))
|
(name.startsWith("AndroidAPS") && name.endsWith(".zip"))
|
||||||
}
|
}
|
||||||
|
@ -81,7 +80,7 @@ class MaintenancePlugin @Inject constructor(
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val exportDir = File(logDirectory, "exports")
|
val exportDir = File(LoggerUtils.logDirectory, "exports")
|
||||||
if (exportDir.exists()) {
|
if (exportDir.exists()) {
|
||||||
val expFiles = exportDir.listFiles()
|
val expFiles = exportDir.listFiles()
|
||||||
for (file in expFiles) {
|
for (file in expFiles) {
|
||||||
|
@ -90,7 +89,6 @@ class MaintenancePlugin @Inject constructor(
|
||||||
exportDir.delete()
|
exportDir.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a list of log files. The number of returned logs is given via the amount
|
* returns a list of log files. The number of returned logs is given via the amount
|
||||||
|
|
|
@ -14,7 +14,7 @@ class BuildHelper @Inject constructor(private val config: Config) {
|
||||||
private var engineeringMode = false
|
private var engineeringMode = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val extFilesDir = LoggerUtils.getLogDirectory()
|
val extFilesDir = LoggerUtils.logDirectory
|
||||||
val engineeringModeSemaphore = File(extFilesDir, "engineering__mode")
|
val engineeringModeSemaphore = File(extFilesDir, "engineering__mode")
|
||||||
|
|
||||||
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile
|
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile
|
||||||
|
|
Loading…
Reference in a new issue