doc/news.texi | 7 +++++++ log.go | 41 +++++++++++++++++++++++++++++++++-------- run.go | 17 +++++++++++------ usage.go | 2 +- diff --git a/doc/news.texi b/doc/news.texi index d3918c9433f6f50c370fe5e5cb576ba18b67896259e0bb2ff26abc20154df0da..2ee69d3874e49df4d7ca26ec8711bc45cf82b590115ddd9880de3662f2d4b406 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -2,6 +2,13 @@ @node News @cindex news @unnumbered News +@anchor{Release 2_2_0} +@section Release 2.2.0 +@itemize +@item + Prefix target's output lines with the name of the target. +@end itemize + @anchor{Release 2_1_0} @section Release 2.1.0 @itemize diff --git a/log.go b/log.go index c46c591b1d386a6dcfd6968db76453b4e2545c22b2d7763dde4a4317d78e9173..a2a5f14bb042bb5db1e5184b54a898a66b86e05e52b42b4aec8f5f00a01f7522 100644 --- a/log.go +++ b/log.go @@ -68,8 +68,9 @@ flagLogLock *bool flagLogPid *bool flagLogJS *bool - LogMutex sync.Mutex - KeyEraseLine string + LogMutex sync.Mutex + KeyEraseLine string + LastLoggedTgt string ) func init() { @@ -108,6 +109,34 @@ } return s + KeyEraseLine + end } +func withPrependedTgt(s string) { + if s[0] != '[' { + stderrWrite(erasedStatus(s, "\n")) + return + } + i := strings.IndexByte(s, ']') + if i == -1 { + stderrWrite(s) + return + } + tgt, s := s[1:i], s[i+1:] + if tgt != LastLoggedTgt { + LastLoggedTgt = tgt + tgt = "redo " + tgt + " ..." + if MyPID != 0 { + tgt = fmt.Sprintf("[%d] %s", MyPID, tgt) + } + stderrWrite(erasedStatus(colourize(CDebug, tgt), "\n")) + } + stderrWrite(erasedStatus(s, "\n")) +} + +func stderrWrite(s string) { + LogMutex.Lock() + os.Stderr.WriteString(s) + LogMutex.Unlock() +} + func tracef(level, format string, args ...interface{}) { var p string if MyPID != 0 { @@ -116,9 +145,7 @@ } switch level { case CNone: p = erasedStatus(StderrPrefix+p+fmt.Sprintf(format, args...), "\n") - LogMutex.Lock() - os.Stderr.WriteString(p) - LogMutex.Unlock() + stderrWrite(p) return case CDebug: if !Debug { @@ -153,9 +180,7 @@ } msg := fmt.Sprintf(format, args...) msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg) msg = erasedStatus(msg, "\n") - LogMutex.Lock() - os.Stderr.WriteString(msg) - LogMutex.Unlock() + stderrWrite(msg) } func colourize(colour, s string) string { diff --git a/run.go b/run.go index 09532cc81110e7ab702e2abafdb547e2ca4089fb7ddfbe7d77f54321ef803deb..a5c842a198e0d43778069c24b6530c7ae6a95f150689400540ff8eece5ad603b 100644 --- a/run.go +++ b/run.go @@ -628,9 +628,11 @@ for scanner.Scan() { line = scanner.Text() if strings.HasPrefix(line, childStderrPrefix) { line = line[len(childStderrPrefix):] - LogMutex.Lock() - os.Stderr.WriteString(StderrPrefix + line + "\n") - LogMutex.Unlock() + if StderrPrefix == "" { + withPrependedTgt(line) + } else { + stderrWrite(StderrPrefix + line + "\n") + } continue } if fdStderr != nil { @@ -640,10 +642,13 @@ } if StderrSilent { continue } - if MyPID == 0 { - tracef(CNone, "%s", line) + if MyPID != 0 { + line = pid + " " + line + } + if StderrPrefix == "" { + withPrependedTgt("[" + tgt.rel + "]" + line) } else { - tracef(CNone, "%s %s", pid, line) + stderrWrite(StderrPrefix + "[" + tgt.rel + "]" + line + "\n") } } close(stderrTerm) diff --git a/usage.go b/usage.go index 056f508e057d8ae2317bac3fdde773a8fd59fdf9d7eee8ecfc7de5b6babf35de..551106383819056f69ae62e8fab377770914174c47747f0762450b3af6b6e5af 100644 --- a/usage.go +++ b/usage.go @@ -24,7 +24,7 @@ "os" ) const ( - Version = "2.1.0" + Version = "2.2.0" Warranty = `Copyright (C) 2020-2023 Sergey Matveev This program is free software: you can redistribute it and/or modify