X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=log.go;h=e671876c5b5aff28ae9e4f4dd22ac14452823df0;hb=c252c75d3f44eac7ea7e88a062e41201cb2997e1;hp=6b91c2d419bc3f6dccca491594c190755bafe108;hpb=734d81bb07d88fb293fefe6f9a0e75eb151dd555;p=goredo.git diff --git a/log.go b/log.go index 6b91c2d..e671876 100644 --- 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 {