1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

More parallel logging work.

This commit is contained in:
Cedric Beust 2016-08-09 00:06:20 -08:00
parent a15cd1769e
commit c073be8eb0
6 changed files with 29 additions and 29 deletions

View file

@ -1,6 +1,5 @@
package com.beust.kobalt
import com.beust.kobalt.misc.log
import java.util.*
/**
@ -75,13 +74,12 @@ class AsciiArt {
return result
}
val defaultLog : (s: String) -> Unit = { log(1, " $it") }
fun logBox(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight,
indent: Int = 0): String {
fun logBox(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight, indent: Int = 0): String {
return buildString {
box(strings, bl, br).forEach {
append(fill(indent)).append(it).append("\n")
val boxLines = box(strings, bl, br)
boxLines.withIndex().forEach { iv ->
append(fill(indent)).append(iv.value)
if (iv.index < boxLines.size - 1) append("\n")
}
}
}
@ -125,7 +123,7 @@ class AsciiTable {
fun headers(vararg names: String) = headers.addAll(names)
private val widths = arrayListOf<Int>()
fun width(w: Int) : Builder {
fun columnWidth(w: Int) : Builder {
widths.add(w)
return this
}
@ -149,6 +147,7 @@ class AsciiTable {
}.joinToString(vb)
val result = StringBuffer().apply {
append(AsciiArt.logBox(formattedHeaders, AsciiArt.bottomLeft2, AsciiArt.bottomRight2))
append("\n")
}
var lineLength = 0
rows.forEachIndexed { index, row ->

View file

@ -81,7 +81,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
val line = listOf(col1("Project"), col2("Build status"), col3("Time"))
.joinToString(AsciiArt.verticalBar)
val table = StringBuffer()
table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10))
table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10) + "\n")
projectStatuses.forEach { pair ->
val projectName = pair.first.name
val cl = listOf(col1(projectName), col2(pair.second.toString()),

View file

@ -271,9 +271,9 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
log(1, "Thread report")
val table = AsciiTable.Builder()
.width(11)
.columnWidth(11)
threadIds.keys.forEach {
table.width(20)
table.columnWidth(24)
}
table.header("Time (sec)")
threadIds.keys.forEach {

View file

@ -12,7 +12,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
interface ILogger {
fun log(tag: String, level: Int, message: String)
fun log(tag: CharSequence, level: Int, message: CharSequence)
}
/**
@ -28,8 +28,8 @@ interface ILogger {
class ParallelLogger @Inject constructor(val args: Args) : ILogger {
enum class Type { LOG, WARN, ERROR }
class LogLine(val name: String? = null, val level: Int, val message: String, val type: Type)
private val logLines = ConcurrentHashMap<String, ArrayList<LogLine>>()
class LogLine(val name: CharSequence? = null, val level: Int, val message: CharSequence, val type: Type)
private val logLines = ConcurrentHashMap<CharSequence, ArrayList<LogLine>>()
private val runningProjects = ConcurrentLinkedQueue<String>()
var startTime: Long? = null
@ -65,9 +65,11 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
}
}
private fun debug(s: String) {
val time = System.currentTimeMillis() - startTime!!
println(" @@@ [$time] $s")
private fun debug(s: CharSequence) {
if (args.log >= 2) {
val time = System.currentTimeMillis() - startTime!!
println(" ### [$time] $s")
}
}
val LOCK = Any()
@ -78,7 +80,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
private fun displayLine(ll: LogLine) {
val time = System.currentTimeMillis() - startTime!!
val m = "### [$time] " + ll.message
val m = (if (args.dev) "### [$time] " else "") + ll.message
when(ll.type) {
Type.LOG -> kobaltLog(ll.level, m)
Type.WARN -> kobaltWarn(m)
@ -86,22 +88,22 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
}
}
private fun emptyProjectLog(name: String?) {
private fun emptyProjectLog(name: CharSequence?) {
val lines = logLines[name]
if (lines != null && lines.any()) {
debug("EMPTY PROJECT LOG FOR $name")
debug("emptyProjectLog($name)")
lines.forEach {
displayLine(it)
}
lines.clear()
debug("DONE EMPTY PROJECT LOG FOR $name")
debug("Done emptyProjectLog($name)")
// logLines.remove(name)
} else if (lines == null) {
throw KobaltException("Didn't call onStartProject() for $name")
}
}
private fun addLogLine(name: String, ll: LogLine) {
private fun addLogLine(name: CharSequence, ll: LogLine) {
if (name != currentName) {
val list = logLines[name] ?: arrayListOf()
logLines[name] = list
@ -112,7 +114,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
}
}
override fun log(tag: String, level: Int, message: String) {
override fun log(tag: CharSequence, level: Int, message: CharSequence) {
if (args.parallel) {
addLogLine(tag, LogLine(tag, level, message, Type.LOG))
} else {

View file

@ -1,6 +1,7 @@
package com.beust.kobalt.internal
import com.beust.kobalt.Args
import com.beust.kobalt.AsciiArt
import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.ITask
import com.beust.kobalt.api.Kobalt
@ -42,7 +43,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
{ task: ITask -> task.plugin.accept(project) })
var lastResult = TaskResult()
kobaltLog.onProjectStarted(project.name)
kobaltLog.log(project.name, 1, "Parallel build of ${project.name} starting")
context.logger.log(project.name, 1, AsciiArt.logBox("Building ${project.name}", indent = 5))
while (graph.freeNodes.any()) {
val toProcess = graph.freeNodes
toProcess.forEach { node ->
@ -50,8 +51,8 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
tasks.forEach { task ->
runBuildListenersForTask(project, context, task.name, start = true)
kobaltLog.log(project.name, 1, "===== " + project.name + ":" + task.name)
// log(1, "===== " + project.name + ":" + task.name)
kobaltLog.log(project.name, 1,
AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${project.name}:${task.name}"))
val thisResult = if (dryRun) TaskResult2(true, null, task) else task.call()
if (lastResult.success) {
lastResult = thisResult
@ -67,8 +68,6 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
runBuildListenersForProject(project, context, false,
if (lastResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILED)
kobaltLog.log(project.name, 1, "Parallel build of ${project.name} ending")
return TaskResult2(lastResult.success, lastResult.errorMessage, this)
}

View file

@ -323,5 +323,5 @@ class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val pluginInfo: Pl
// override val timeOut : Long = 10000
override val priority: Int = 0
override val name: String get() = "[Taskworker " + tasks.map { it.toString() }.joinToString(",") + "]"
override val name: String get() = "[Taskworker " + tasks.map(ITask::toString).joinToString(",") + "]"
}