X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=log.go;h=ebfb39493043b630f6b839ff75d6cecd54c0a91c;hb=66de71f560cd772e7ef9e9cf1182ce67e495b1ec;hp=f4fa2ca9c65f647b8aa1d48d71232984b76bed90;hpb=e14100898b08c312919f58f712f19f623f602748;p=goredo.git diff --git a/log.go b/log.go index f4fa2ca..ebfb394 100644 --- a/log.go +++ b/log.go @@ -24,6 +24,7 @@ import ( "fmt" "os" "strings" + "sync" ) const ( @@ -65,11 +66,13 @@ var ( LogJS bool MyPid int - flagDebug = flag.Bool("debug", false, "enable debug logging (REDO_DEBUG=1)") - flagLogWait = flag.Bool("log-wait", false, "enable wait messages logging (REDO_LOG_WAIT=1)") - flagLogLock = flag.Bool("log-lock", false, "enable lock messages logging (REDO_LOG_LOCK=1)") - flagLogPid = flag.Bool("log-pid", false, "append PIDs (REDO_LOG_PID=1)") - flagLogJS = flag.Bool("log-js", false, "enable jobserver messages logging (REDO_LOG_JS=1)") + 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{}) { @@ -79,7 +82,9 @@ 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 { @@ -110,7 +115,9 @@ func trace(level, format string, args ...interface{}) { } 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 {