Commit 1ba3c14f authored by Diederik Loerakker's avatar Diederik Loerakker Committed by GitHub

op-node/testlog: auto-adjust padding for test log alignment (#2928)

Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 5d8a9828
......@@ -135,17 +135,23 @@ func (l *logger) SetHandler(h log.Handler) {
l.l.SetHandler(h)
}
// tracks the largest seen decoration length, to make alignment between all test loggers consistent.
var logDecorationLength = 12
// flush writes all buffered messages and clears the buffer.
func (l *logger) flush() {
l.t.Helper()
// 2 frame skip for flush() + public logger fn
decorationLen := estimateInfoLen(2)
padding := 20
if decorationLen <= 25 {
padding = 25 - decorationLen
if decorationLen > 30 { // limit to a maximum size, to avoid huge padding
decorationLen = 30
}
// logDecorationLength is only increasing, should be safe even with inaccurate concurrent use.
if decorationLen > logDecorationLength { // increase padding if we encounter larger decoration
logDecorationLength = decorationLen
}
for _, r := range l.h.buf {
l.t.Logf("%*s%s", padding, "", l.h.fmt.Format(r))
l.t.Logf("%*s%s", logDecorationLength-decorationLen, "", l.h.fmt.Format(r))
}
l.h.buf = nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment