Commit af61ac38 authored by Ricki Hirner's avatar Ricki Hirner

Optimize logging

parent 2e9f1d2d
......@@ -32,14 +32,11 @@ object Logger {
@JvmField
val log = Logger.getLogger("davdroid")!!
init {
at.bitfire.dav4android.Constants.log = Logger.getLogger("davdroid.dav4android")
at.bitfire.cert4android.Constants.log = Logger.getLogger("davdroid.cert4android")
}
fun reinitLogger(context: Context) {
ServiceDB.OpenHelper(context).use { dbHelper ->
val settings = Settings(dbHelper.getReadableDatabase())
val settings = Settings(dbHelper.readableDatabase)
val logToFile = settings.getBoolean(App.LOG_TO_EXTERNAL_STORAGE, false)
val logVerbose = logToFile || Log.isLoggable(log.name, Log.DEBUG)
......@@ -72,7 +69,7 @@ object Logger {
val fileHandler = FileHandler(fileName)
fileHandler.formatter = PlainTextFormatter.DEFAULT
log.addHandler(fileHandler)
rootLogger.addHandler(fileHandler)
val prefIntent = Intent(context, AppSettingsActivity::class.java)
prefIntent.putExtra(AppSettingsActivity.EXTRA_SCROLL_TO, "log_to_external_storage")
......@@ -86,7 +83,7 @@ object Logger {
.bigText(context.getString(R.string.logging_to_external_storage, dir.path)))
.setOngoing(true)
} catch (e: IOException) {
} catch(e: IOException) {
log.log(Level.SEVERE, "Couldn't create external log file", e)
builder .setContentText(context.getString(R.string.logging_couldnt_create_file, e.localizedMessage))
......
......@@ -29,11 +29,9 @@ class PlainTextFormatter private constructor(
builder .append(DateFormatUtils.format(r.millis, "yyyy-MM-dd HH:mm:ss"))
.append(" ").append(r.threadID).append(" ")
if (r.sourceClassName.replaceFirst("\\$.*", "") != r.loggerName) {
val className = shortClassName(r.sourceClassName)
if (className != "ical4android.AndroidAppender")
builder.append("[").append(className).append("] ")
}
val className = shortClassName(r.sourceClassName)
if (className != r.loggerName)
builder.append("[").append(className).append("] ")
builder.append(r.message)
......@@ -54,8 +52,7 @@ class PlainTextFormatter private constructor(
}
private fun shortClassName(className: String) = className
.replace("at.bitfire.davdroid.", "")
.replace("at.bitfire.", "")
.replace(Regex("^at\\.bitfire\\.(dav|cert4an|dav4an|ical4an|vcard4an)droid\\."), "")
.replace(Regex("\\$.*$"), "")
}
Subproject commit 3cff6c85a7df1b10644e1ce85cbd5b55023b433c
Subproject commit b5cea7a16ffd9cffa406f10b0510d1b57313d5d2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment