From 83959534021b5547befc7b7afd82b9a4846704f9 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Tue, 13 Feb 2024 16:22:02 -0500 Subject: [PATCH] Cleanup some log messages when logging is not verbose --- .../mineinabyss/geary/autoscan/AutoScanner.kt | 8 ++++++-- .../geary/autoscan/AutoScannerDSL.kt | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt index f6b48be97..f23d328a7 100644 --- a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt +++ b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt @@ -1,5 +1,6 @@ package com.mineinabyss.geary.autoscan +import co.touchlab.kermit.Severity import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault import com.mineinabyss.geary.modules.geary @@ -28,8 +29,11 @@ interface AutoScanner { .filterIsInstance() .onEach { geary.pipeline.addSystem(it) } .map { it::class.simpleName } - .joinToString() - .let { logger.i("Autoscan loaded singleton systems: $it") } + .let { + if (logger.config.minSeverity <= Severity.Verbose) + logger.i("Autoscan loaded singleton systems: ${it.joinToString()}") + else logger.i("Autoscan loaded ${it.count()} singleton systems") + } } } diff --git a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt index 5aca91d45..83bac5a8a 100644 --- a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt +++ b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt @@ -1,5 +1,6 @@ package com.mineinabyss.geary.autoscan +import co.touchlab.kermit.Severity import com.mineinabyss.geary.addons.dsl.GearyDSL import com.mineinabyss.geary.datatypes.Component import com.mineinabyss.geary.modules.GearyConfiguration @@ -61,6 +62,7 @@ class AutoScannerDSL( .asSequence() .map { it.kotlin } .filter { !it.hasAnnotation() } + .toList() geary { serialization { @@ -68,17 +70,19 @@ class AutoScannerDSL( scanned.forEach { scannedComponent -> runCatching { component(scannedComponent) } .onFailure { - if (it is ClassNotFoundException) - this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}, class not found") - else - this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}") + when { + geary.logger.config.minSeverity <= Severity.Verbose -> geary.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}") + else -> geary.logger.w("Failed to register component ${scannedComponent.simpleName} ${it::class.simpleName}: ${it.message}") + } } } } } } - logger.i("Autoscan found components: ${scanned.joinToString { it.simpleName!! }}") + if (logger.config.minSeverity <= Severity.Verbose) + logger.i("Autoscan found components: ${scanned.joinToString { it.simpleName!! }} in packages $limitTo") + else logger.i("Autoscan found ${scanned.size} components in packages $limitTo") autoScanner.scannedComponents += scanned } @@ -114,12 +118,15 @@ class AutoScannerDSL( .map { it.kotlin } .filter { !it.hasAnnotation() } .filterIsInstance>() + .toList() scanned.forEach { scannedClass -> runCatching { subclass(scannedClass, scannedClass.serializer()) } .onFailure { this@AutoScannerDSL.logger.w("Failed to load subclass ${scannedClass.simpleName} of ${kClass.simpleName}") } } - this@AutoScannerDSL.logger.i("Autoscan found subclasses for ${kClass.simpleName}: ${scanned.joinToString { it.simpleName!! }}") + if (geary.logger.config.minSeverity <= Severity.Verbose) + geary.logger.i("Autoscan found subclasses for ${kClass.simpleName}: ${scanned.joinToString { it.simpleName!! }}") + else geary.logger.i("Autoscan found ${scanned.size} subclasses for ${kClass.simpleName}") } } }