From 9e15f07aefe6ea1f366466c6721b92e77e3f1b41 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Tue, 22 Jun 2021 15:17:55 +0200 Subject: Logging in CLI (#1976) --- runners/cli/api/cli.api | 2 ++ runners/cli/src/main/kotlin/cli/main.kt | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'runners/cli') diff --git a/runners/cli/api/cli.api b/runners/cli/api/cli.api index f2f1fe44..b7ea94ff 100644 --- a/runners/cli/api/cli.api +++ b/runners/cli/api/cli.api @@ -64,6 +64,8 @@ public final class org/jetbrains/dokka/GlobalArguments : org/jetbrains/dokka/Dok public final fun getHelpSourceSet ()Ljava/lang/Object; public fun getIncludes ()Ljava/util/Set; public final fun getJson ()Ljava/lang/String; + public final fun getLogger ()Lorg/jetbrains/dokka/utilities/DokkaLogger; + public final fun getLoggingLevel ()Lorg/jetbrains/dokka/utilities/LoggingLevel; public fun getModuleName ()Ljava/lang/String; public fun getModuleVersion ()Ljava/lang/String; public fun getModules ()Ljava/util/List; diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 36edb2d9..7a7a5582 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -3,6 +3,8 @@ package org.jetbrains.dokka import kotlinx.cli.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.jetbrains.dokka.utilities.DokkaLogger +import org.jetbrains.dokka.utilities.LoggingLevel import org.jetbrains.dokka.utilities.cast import java.io.* import java.net.MalformedURLException @@ -108,8 +110,28 @@ class GlobalArguments(args: Array) : DokkaConfiguration { description = "Prints help for single -sourceSet" ) + val loggingLevel by parser.option( + ArgType.Choice(toVariant = { + when (it.toUpperCase().trim()) { + "DEBUG", "" -> LoggingLevel.DEBUG + "PROGRESS" -> LoggingLevel.PROGRESS + "INFO" -> LoggingLevel.INFO + "WARN" -> LoggingLevel.WARN + "ERROR" -> LoggingLevel.ERROR + else -> { + println("""Failed to deserialize logging level, got $it expected one of "DEBUG", "PROGRESS", "INFO", "WARN", "ERROR", falling back to DEBUG""") + LoggingLevel.DEBUG + } + } + }, toString = { it.toString() } + )).default(LoggingLevel.DEBUG) + override val modules: List = emptyList() + val logger: DokkaLogger by lazy { + DokkaConsoleLogger(loggingLevel) + } + init { parser.parse(args) @@ -129,7 +151,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { .add(SourceLinkDefinitionImpl.parseSourceLinkDefinition(it)) } else { - DokkaConsoleLogger.warn("Invalid -srcLink syntax. Expected: =[#lineSuffix]. No source links will be generated.") + logger.warn("Invalid -srcLink syntax. Expected: =[#lineSuffix]. No source links will be generated.") } } @@ -378,6 +400,6 @@ fun main(args: Array) { ) else globalArguments - DokkaGenerator(configuration, DokkaConsoleLogger).generate() + DokkaGenerator(configuration, globalArguments.logger).generate() } -- cgit