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

Log clean up.

This commit is contained in:
Cedric Beust 2016-08-08 23:31:05 -08:00
parent a55256133e
commit a15cd1769e
5 changed files with 22 additions and 20 deletions

View file

@ -75,20 +75,21 @@ class AsciiArt {
return result
}
private fun fill(n: Int) = StringBuffer().apply { repeat(n, { append(" ")})}.toString()
val defaultLog : (s: String) -> Unit = { log(1, " $it") }
fun logBox(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight,
print: (String) -> Unit = defaultLog) {
indent: Int = 0): String {
return buildString {
box(strings, bl, br).forEach {
print(it)
append(fill(indent)).append(it).append("\n")
}
}
}
fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, print: (String) -> Unit = defaultLog) {
logBox(listOf(s), bl, br, print)
}
fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, indent: Int = 0)
= logBox(listOf(s), bl, br, indent)
fun fill(n: Int) = buildString { repeat(n, { append(" ")})}.toString()
fun center(s: String, width: Int) : String {
val diff = width - s.length
@ -139,23 +140,24 @@ class AsciiTable {
}
val vb = AsciiArt.verticalBar
fun build() : String {
val formattedHeaders =
headers.mapIndexed { index, s ->
val s2 = col(widths[index], s)
s2
}.joinToString(vb)
val result = buildString {
val result = StringBuffer().apply {
append(AsciiArt.logBox(formattedHeaders, AsciiArt.bottomLeft2, AsciiArt.bottomRight2))
}
var lineLength = 0
rows.forEachIndexed { index, row ->
val formattedRow = row.mapIndexed { i, s -> col(widths[i], s) }.joinToString(vb)
val line = vb + " " + formattedRow + " " + vb
AsciiArt.defaultLog(line)
result.append(line).append("\n")
lineLength = line.length
}
AsciiArt.defaultLog(AsciiArt.lowerBox(lineLength - 4))
result.append(AsciiArt.lowerBox(lineLength - 4))
return result.toString()
}

View file

@ -42,7 +42,7 @@ class ResolveDependency @Inject constructor(
val seen = hashSetOf(dep.id)
root.addChildren(findChildren(root, seen))
AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" })
log(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }))
display(root.children)
println("")

View file

@ -80,15 +80,17 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
// if (timings.size > 1 && hasFailures) {
val line = listOf(col1("Project"), col2("Build status"), col3("Time"))
.joinToString(AsciiArt.verticalBar)
AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2)
val table = StringBuffer()
table.append(AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2, indent = 10))
projectStatuses.forEach { pair ->
val projectName = pair.first.name
val cl = listOf(col1(projectName), col2(pair.second.toString()),
col3(formatMillisLeft(projectInfos[projectName]!!.durationMillis, 8)))
.joinToString(AsciiArt.verticalBar)
log(1, " " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar)
table.append(" " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar + "\n")
}
log(1, " " + AsciiArt.lowerBox(line.length))
table.append(" " + AsciiArt.lowerBox(line.length))
log(1, table.toString())
// }
}

View file

@ -276,11 +276,9 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
table.width(20)
}
table.header("Time (sec)")
val header = StringBuffer().apply {
threadIds.keys.forEach {
table.header("Thread " + it.toString())
}
}
fun toSeconds(millis: Long) = (millis / 1000).toInt().toString()

View file

@ -34,7 +34,7 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap<String
val context = Kobalt.context!!
projects.forEach { project ->
AsciiArt.logBox("Building ${project.name}")
log(1, AsciiArt.logBox("Building ${project.name}", indent = 5))
// Does the current project depend on any failed projects?
val fp = project.dependsOn.filter { failedProjects.contains(it.name) }.map(Project::name)