X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=log.go;h=3064a7ad4b1d5dbf1a690c6a585e80d78502ec41;hb=4274dce3366cee45bfaccbe5ca340ce6efe68e00;hp=f4248de80d30a9d73146d688489f0d18efb2b886;hpb=ff2443f496cbf7f648b84a78e468dc3f130c37f2;p=goredo.git diff --git a/log.go b/log.go index f4248de..3064a7a 100644 --- a/log.go +++ b/log.go @@ -61,16 +61,15 @@ var ( CReset string CNone string = "NONE" - flagNoProgress = flag.Bool("no-progress", false, fmt.Sprintf("no progress printing (%s=1), also implies -no-status", EnvNoProgress)) 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)) + flagNoProgress *bool + flagLogWait *bool + flagLogLock *bool + flagLogPid *bool + flagLogJS *bool LogMutex sync.Mutex KeyEraseLine string - LogWasStatus bool ) func init() { @@ -85,13 +84,28 @@ func init() { CJS = string(t.Escape.White) CReset = string(t.Escape.Reset) KeyEraseLine = fmt.Sprintf("%s[K", CReset[0:1]) + + cmdName := CmdName() + if !(cmdName == CmdNameRedo || cmdName == CmdNameRedoIfchange) { + return + } + flagNoProgress = flag.Bool("no-progress", false, + fmt.Sprintf("no progress printing (%s=1), also implies -no-status", EnvNoProgress)) + 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)) } func erasedStatus(s, end string) string { - if LogWasStatus { - s += KeyEraseLine + if NoProgress { + return s + end } - return s + end + return s + KeyEraseLine + end } func trace(level, format string, args ...interface{}) { @@ -101,10 +115,9 @@ func trace(level, format string, args ...interface{}) { } switch level { case CNone: - p = StderrPrefix + p + fmt.Sprintf(format, args...) + p = erasedStatus(StderrPrefix+p+fmt.Sprintf(format, args...), "\n") LogMutex.Lock() - os.Stderr.WriteString(erasedStatus(p, "\n")) - LogWasStatus = false + os.Stderr.WriteString(p) LogMutex.Unlock() return case CDebug: @@ -139,9 +152,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(erasedStatus(msg, "\n")) - LogWasStatus = false + os.Stderr.WriteString(msg) LogMutex.Unlock() }