Skip to content

Commit

Permalink
Cleanup some log messages when logging is not verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Feb 13, 2024
1 parent 87f8232 commit 8395953
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,8 +29,11 @@ interface AutoScanner {
.filterIsInstance<System>()
.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")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -61,24 +62,27 @@ class AutoScannerDSL(
.asSequence()
.map { it.kotlin }
.filter { !it.hasAnnotation<ExcludeAutoScan>() }
.toList()

geary {
serialization {
components {
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
}
Expand Down Expand Up @@ -114,12 +118,15 @@ class AutoScannerDSL(
.map { it.kotlin }
.filter { !it.hasAnnotation<ExcludeAutoScan>() }
.filterIsInstance<KClass<T>>()
.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}")
}
}
}
Expand Down

0 comments on commit 8395953

Please sign in to comment.