X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=log.go;h=4d8a982813a1e58a31c43fafbcad3f4d2d4336dd;hb=d830f32d30e4ea9d9f06ae835db6ec5c4822dcfc;hp=e1586c7907586f9830e603e7f64b2bcd3c78081c;hpb=a3d6bbf97e90bf923142d061bc68b28cc1dec2a8;p=goredo.git diff --git a/log.go b/log.go index e1586c7..4d8a982 100644 --- a/log.go +++ b/log.go @@ -1,6 +1,6 @@ /* -goredo -- redo implementation on pure Go -Copyright (C) 2020 Sergey Matveev +goredo -- djb's redo implementation on pure Go +Copyright (C) 2020-2021 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,14 +62,14 @@ var ( CNone string = "NONE" flagNoProgress = flag.Bool("no-progress", false, fmt.Sprintf("no progress printing (%s=1), also implies -no-status", EnvNoProgress)) - flagDebug = flag.Bool("debug", false, fmt.Sprintf("enable debug logging (%s=1)", EnvDebug)) + flagDebug = flag.Bool("d", false, fmt.Sprintf("enable debug logging (%s=1)", EnvDebug)) flagLogWait = flag.Bool("log-wait", false, fmt.Sprintf("enable wait messages logging (%s=1)", EnvLogWait)) flagLogLock = flag.Bool("log-lock", false, fmt.Sprintf("enable lock messages logging (%s=1)", EnvLogLock)) flagLogPid = flag.Bool("log-pid", false, fmt.Sprintf("append PIDs (%s=1)", EnvLogPid)) flagLogJS = flag.Bool("log-js", false, fmt.Sprintf("enable jobserver messages logging (%s=1)", EnvLogJS)) - LogMutex sync.Mutex - LogLenPrev int + LogMutex sync.Mutex + KeyEraseLine string ) func init() { @@ -83,17 +83,14 @@ func init() { CWarn = string(t.Escape.Magenta) CJS = string(t.Escape.White) CReset = string(t.Escape.Reset) + KeyEraseLine = fmt.Sprintf("%s[K", CReset[0:1]) } -func fillUpToTermSize(s, end string) string { - sLen := len(s) - if sLen < LogLenPrev { - s += strings.Repeat(" ", LogLenPrev-sLen) - LogLenPrev = sLen - } else { - LogLenPrev = sLen +func erasedStatus(s, end string) string { + if NoProgress { + return s + end } - return s + end + return s + KeyEraseLine + end } func trace(level, format string, args ...interface{}) { @@ -103,10 +100,9 @@ func trace(level, format string, args ...interface{}) { } switch level { case CNone: + p = erasedStatus(StderrPrefix+p+fmt.Sprintf(format, args...), "\n") LogMutex.Lock() - os.Stderr.WriteString(fillUpToTermSize( - StderrPrefix+p+fmt.Sprintf(format, args...), "\n", - )) + os.Stderr.WriteString(p) LogMutex.Unlock() return case CDebug: @@ -141,8 +137,9 @@ func trace(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(fillUpToTermSize(msg, "\n")) + os.Stderr.WriteString(msg) LogMutex.Unlock() }