package main
import (
+ "flag"
"fmt"
"os"
"strings"
+ "sync"
)
const (
+ EnvLevel = "REDO_LEVEL"
+ EnvDebug = "REDO_DEBUG"
+ EnvLogWait = "REDO_LOG_WAIT"
+ EnvLogLock = "REDO_LOG_LOCK"
+ EnvLogPid = "REDO_LOG_PID"
+ EnvLogJS = "REDO_LOG_JS"
+ EnvNoColor = "NO_COLOR"
+
CReset = "\033[0m"
CBold = "\033[1m"
CBlack = "\033[30;1m"
CDebug = CYellow
CRedo = CGreen
- CDone = CBlue
+ CWait = CBlue
CLock = CCyan
CErr = CRed
CWarn = CMagenta
)
var (
+ Level = 0
NoColor bool
Debug bool
- LogDone bool
+ LogWait bool
LogLock bool
LogJS bool
MyPid int
+
+ flagDebug = flag.Bool("debug", 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
)
func trace(level, format string, args ...interface{}) {
}
switch level {
case CNone:
+ LogMutex.Lock()
os.Stderr.WriteString(StderrPrefix + p + fmt.Sprintf(format+"\n", args...))
+ LogMutex.Unlock()
return
case CDebug:
if !Debug {
return
}
p += "dbg "
- case CRedo:
- p += "redo "
- case CDone:
- if !(LogDone || Debug) {
+ case CWait:
+ if !(LogWait || Debug) {
return
}
- p += "done "
+ p += "wait "
+ case CRedo:
+ p += "redo "
case CLock:
if !(LogLock || Debug) {
return
}
msg := fmt.Sprintf(format, args...)
msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg)
+ LogMutex.Lock()
os.Stderr.WriteString(msg + "\n")
+ LogMutex.Unlock()
}
func colourize(colour, s string) string {