]> Cypherpunks.ru repositories - goredo.git/commitdiff
Prefix target's output with the name v2.2.0
authorSergey Matveev <stargrave@stargrave.org>
Mon, 16 Oct 2023 13:07:47 +0000 (16:07 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 16 Oct 2023 13:16:47 +0000 (16:16 +0300)
doc/news.texi
log.go
run.go
usage.go

index 1ab170abeda82ea5d2c82d41308330cf79d40455..68442f02066429dd70b216f6c18caa90ce57141f 100644 (file)
@@ -2,6 +2,13 @@
 @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 6b91c2d419bc3f6dccca491594c190755bafe108..e671876c5b5aff28ae9e4f4dd22ac14452823df0 100644 (file)
--- a/log.go
+++ b/log.go
@@ -68,8 +68,9 @@ var (
        flagLogPid     *bool
        flagLogJS      *bool
 
-       LogMutex     sync.Mutex
-       KeyEraseLine string
+       LogMutex      sync.Mutex
+       KeyEraseLine  string
+       LastLoggedTgt string
 )
 
 func init() {
@@ -108,6 +109,34 @@ func erasedStatus(s, end string) string {
        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 @@ func tracef(level, format string, args ...interface{}) {
        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 @@ func tracef(level, format string, args ...interface{}) {
        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 816f962e25bc23a18f369872fc8730544078dd5a..3fd4168eef99a4f1feae35302af8abac03157d2e 100644 (file)
--- a/run.go
+++ b/run.go
@@ -628,9 +628,11 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                                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 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                                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)
index ca592b08aaf5b0f83d96a84a8889dc5499a6f2e4..28036282fe0801c72ed89f5f69427666b43f99f2 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -24,7 +24,7 @@ import (
 )
 
 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