Skip to content

Commit

Permalink
Allow users to specify their own logger through FlavorOptions.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
GrowlyX committed Jan 2, 2022
1 parent 4278fb9 commit a229883
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/kotlin/gg/scala/flavor/Flavor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import kotlin.reflect.KClass
* @since 1/2/2022
*/
class Flavor(
private val initializer: KClass<*>
private val initializer: KClass<*>,
private val options: FlavorOptions
)
{
companion object
{
@JvmStatic
inline fun <reified T> create(): Flavor
inline fun <reified T> create(
options: FlavorOptions = FlavorOptions()
): Flavor
{
return Flavor(T::class)
return Flavor(T::class, options)
}
}

Expand Down Expand Up @@ -84,8 +87,8 @@ class Flavor(
close?.invoke(entry.value)
}

Logger.getAnonymousLogger().info {
"[Flavor] Shutdown [${
options.logger.info {
"[Services] Shutdown [${
service?.name ?: entry.key
.java.simpleName
}] in ${milli}ms."
Expand Down Expand Up @@ -160,8 +163,8 @@ class Flavor(
configure?.invoke(singleton)
}

Logger.getAnonymousLogger().info {
"[Flavor] Loaded [${
options.logger.info {
"[Services] Loaded [${
service.name.ifEmpty {
clazz.java.simpleName
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/gg/scala/flavor/FlavorOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gg.scala.flavor

import java.util.logging.Logger

/**
* @author GrowlyX
* @since 1/2/2022
*/
data class FlavorOptions
@JvmOverloads
constructor(
val logger: Logger = Logger.getAnonymousLogger()
)

0 comments on commit a229883

Please sign in to comment.