[Commonizer] Logging: Implement CommonizerLogLevel and hide verbose output by default
^KT-36679 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
7349ec8f2f
commit
b48850c993
@@ -5,24 +5,34 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerLogLevel
|
||||
import org.jetbrains.kotlin.util.Logger
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
internal class CliLoggerAdapter(indentSize: Int = 0) : Logger {
|
||||
|
||||
internal class CliLoggerAdapter(
|
||||
private val level: CommonizerLogLevel,
|
||||
indentSize: Int = 0
|
||||
) : Logger {
|
||||
private val indent = " ".repeat(indentSize)
|
||||
|
||||
override fun log(message: String) = printlnIndented(message)
|
||||
override fun log(message: String) = printlnIndented(message, CommonizerLogLevel.Info)
|
||||
|
||||
override fun warning(message: String) = printlnIndented("Warning: $message")
|
||||
override fun warning(message: String) = printlnIndented("Warning: $message", *CommonizerLogLevel.values())
|
||||
|
||||
override fun error(message: String) = fatal(message)
|
||||
|
||||
override fun fatal(message: String): Nothing {
|
||||
printlnIndented("Error: $message\n")
|
||||
printlnIndented("Error: $message\n", *CommonizerLogLevel.values())
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
private fun printlnIndented(text: String) =
|
||||
if (indent.isEmpty()) println(text)
|
||||
else text.split('\n').forEach { println(indent + it) }
|
||||
private fun printlnIndented(text: String, vararg levels: CommonizerLogLevel) {
|
||||
if (level in levels) {
|
||||
if (indent.isEmpty()) println(text)
|
||||
else text.split('\n').forEach {
|
||||
println(indent + it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.commonizer.cli
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerLogLevel
|
||||
|
||||
internal object LogLevelOptionType : OptionType<CommonizerLogLevel>("log-level", "{quiet, info}", false) {
|
||||
override fun parse(rawValue: String, onError: (reason: String) -> Nothing): Option<CommonizerLogLevel> {
|
||||
return when (rawValue.lowercase().trim()) {
|
||||
"quiet" -> Option(this, CommonizerLogLevel.Quiet)
|
||||
"info" -> Option(this, CommonizerLogLevel.Info)
|
||||
else -> Option(this, CommonizerLogLevel.Quiet)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ internal abstract class Task(private val options: Collection<Option<*>>) : Compa
|
||||
INFORMATIONAL,
|
||||
COMMONIZATION(
|
||||
prologue = null,
|
||||
epilogue = "\n",
|
||||
epilogue = null,
|
||||
logEachStep = true
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ internal enum class TaskType(
|
||||
"Boolean (default false);\nwhether to copy Kotlin/Native endorsed libraries to the destination",
|
||||
mandatory = false
|
||||
),
|
||||
StatsTypeOptionType
|
||||
StatsTypeOptionType,
|
||||
LogLevelOptionType,
|
||||
),
|
||||
::NativeDistributionCommonize
|
||||
),
|
||||
@@ -52,6 +53,7 @@ internal enum class TaskType(
|
||||
InputLibrariesOptionType,
|
||||
DependencyLibrariesOptionType,
|
||||
OutputCommonizerTargetOptionType,
|
||||
LogLevelOptionType
|
||||
),
|
||||
::NativeKlibCommonize
|
||||
)
|
||||
|
||||
@@ -50,12 +50,14 @@ internal class NativeKlibCommonize(options: Collection<Option<*>>) : Task(option
|
||||
val dependencyLibraries = getOptional<List<CommonizerDependency>, DependencyLibrariesOptionType>().orEmpty()
|
||||
val outputCommonizerTarget = compatGetOutputTarget()
|
||||
val statsType = getOptional<StatsType, StatsTypeOptionType> { it == "log-stats" } ?: StatsType.NONE
|
||||
val logLevel = getOptional<CommonizerLogLevel, LogLevelOptionType>() ?: CommonizerLogLevel.Quiet
|
||||
|
||||
|
||||
val konanTargets = outputCommonizerTarget.konanTargets
|
||||
val commonizerTargets = konanTargets.map(::CommonizerTarget)
|
||||
|
||||
val progressLogger = ProgressLogger(CliLoggerAdapter(2))
|
||||
val libraryLoader = DefaultNativeLibraryLoader(progressLogger)
|
||||
val logger = ProgressLogger(CliLoggerAdapter(logLevel, 2))
|
||||
val libraryLoader = DefaultNativeLibraryLoader(logger)
|
||||
val statsCollector = StatsCollector(statsType, commonizerTargets)
|
||||
val repository = FilesRepository(targetLibraries.toSet(), libraryLoader)
|
||||
|
||||
@@ -74,7 +76,7 @@ internal class NativeKlibCommonize(options: Collection<Option<*>>) : Task(option
|
||||
CommonizerDependencyRepository(dependencyLibraries.toSet(), libraryLoader),
|
||||
resultsConsumer = resultsConsumer,
|
||||
statsCollector = statsCollector,
|
||||
progressLogger = progressLogger
|
||||
progressLogger = logger
|
||||
).run()
|
||||
|
||||
statsCollector?.writeTo(FileStatsOutput(destination, statsType.name.lowercase()))
|
||||
@@ -97,9 +99,10 @@ internal class NativeDistributionCommonize(options: Collection<Option<*>>) : Tas
|
||||
val copyStdlib = getOptional<Boolean, BooleanOptionType> { it == "copy-stdlib" } ?: false
|
||||
val copyEndorsedLibs = getOptional<Boolean, BooleanOptionType> { it == "copy-endorsed-libs" } ?: false
|
||||
val statsType = getOptional<StatsType, StatsTypeOptionType> { it == "log-stats" } ?: StatsType.NONE
|
||||
val logLevel = getOptional<CommonizerLogLevel, LogLevelOptionType>() ?: CommonizerLogLevel.Quiet
|
||||
|
||||
val progressLogger = ProgressLogger(CliLoggerAdapter(2))
|
||||
val libraryLoader = DefaultNativeLibraryLoader(progressLogger)
|
||||
val logger = ProgressLogger(CliLoggerAdapter(logLevel, 2))
|
||||
val libraryLoader = DefaultNativeLibraryLoader(logger)
|
||||
val repository = KonanDistributionRepository(distribution, outputTarget.konanTargets, libraryLoader)
|
||||
val statsCollector = StatsCollector(statsType, outputTarget.withAllAncestors().toList())
|
||||
|
||||
@@ -112,8 +115,7 @@ internal class NativeDistributionCommonize(options: Collection<Option<*>>) : Tas
|
||||
}
|
||||
|
||||
val descriptionSuffix = estimateLibrariesCount(repository, outputTarget.allLeaves()).let { " ($it items)" }
|
||||
val description = "${logPrefix}Preparing commonized Kotlin/Native libraries for $outputTarget$descriptionSuffix"
|
||||
println(description)
|
||||
logger.log("${logPrefix}Preparing commonized Kotlin/Native libraries for $outputTarget$descriptionSuffix")
|
||||
|
||||
LibraryCommonizer(
|
||||
outputTarget = outputTarget,
|
||||
@@ -121,7 +123,7 @@ internal class NativeDistributionCommonize(options: Collection<Option<*>>) : Tas
|
||||
dependencies = StdlibRepository(distribution, libraryLoader),
|
||||
resultsConsumer = resultsConsumer,
|
||||
statsCollector = statsCollector,
|
||||
progressLogger = progressLogger
|
||||
progressLogger = logger
|
||||
).run()
|
||||
|
||||
statsCollector?.writeTo(FileStatsOutput(destination, statsType.name.lowercase()))
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
package org.jetbrains.kotlin.commonizer.utils
|
||||
|
||||
import org.jetbrains.kotlin.commonizer.cli.CliLoggerAdapter
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerLogLevel
|
||||
import org.jetbrains.kotlin.util.Logger
|
||||
|
||||
class ProgressLogger(
|
||||
private val wrapped: Logger = CliLoggerAdapter(0),
|
||||
private val wrapped: Logger = CliLoggerAdapter(CommonizerLogLevel.Info, 0),
|
||||
private val indent: Int = 0,
|
||||
) : Logger by wrapped {
|
||||
private val clockMark = ResettableClockMark()
|
||||
|
||||
Reference in New Issue
Block a user