From 4a3ae4e5fb0e79ada8956ba611c6bf36f76fc5f2 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Tue, 26 Sep 2017 18:56:45 +0200
Subject: [PATCH] Improved loggability handling

---
 .../main/java/de/kuschku/quasseldroid_ng/ui/MainActivity.kt | 5 ++---
 .../kuschku/libquassel/util/compatibility/LoggingHandler.kt | 6 +++---
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/MainActivity.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/MainActivity.kt
index 93f8a9a3c..839a930ec 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/MainActivity.kt
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/MainActivity.kt
@@ -58,8 +58,6 @@ class MainActivity : ServiceBoundActivity() {
   private val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_TIME
   private val handler = object : LoggingHandler() {
     override fun log(logLevel: LogLevel, tag: String, message: String?, throwable: Throwable?) {
-      if (logLevel.ordinal < LogLevel.INFO.ordinal)
-        return
       val time = dateTimeFormatter.format(ZonedDateTime.now(ZoneOffset.UTC))
       runOnUiThread {
         errorList.append("$time $tag: ")
@@ -74,7 +72,8 @@ class MainActivity : ServiceBoundActivity() {
       }
     }
 
-    override fun isLoggable(logLevel: LogLevel, tag: String) = true
+    override fun isLoggable(logLevel: LogLevel, tag: String)
+      = (logLevel.ordinal >= LogLevel.INFO.ordinal)
   }
 
   override fun onCreate(savedInstanceState: Bundle?) {
diff --git a/lib/src/main/java/de/kuschku/libquassel/util/compatibility/LoggingHandler.kt b/lib/src/main/java/de/kuschku/libquassel/util/compatibility/LoggingHandler.kt
index 1ab563f8a..261b46ea0 100644
--- a/lib/src/main/java/de/kuschku/libquassel/util/compatibility/LoggingHandler.kt
+++ b/lib/src/main/java/de/kuschku/libquassel/util/compatibility/LoggingHandler.kt
@@ -37,9 +37,9 @@ abstract class LoggingHandler {
 
 inline fun log(logLevel: LoggingHandler.LogLevel, tag: String, message: String? = null,
                throwable: Throwable? = null) {
-  for (it in LoggingHandler.loggingHandlers) {
-    it.log(logLevel, tag, message, throwable)
-  }
+  LoggingHandler.loggingHandlers
+    .filter { it.isLoggable(logLevel, tag) }
+    .forEach { it.log(logLevel, tag, message, throwable) }
 }
 
 inline fun log(logLevel: LoggingHandler.LogLevel, tag: String, throwable: Throwable? = null)
-- 
GitLab