2 goredo -- redo implementation on pure Go
3 Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 EnvLevel = "REDO_LEVEL"
31 EnvDebug = "REDO_DEBUG"
32 EnvLogWait = "REDO_LOG_WAIT"
33 EnvLogLock = "REDO_LOG_LOCK"
34 EnvLogPid = "REDO_LOG_PID"
35 EnvLogJS = "REDO_LOG_JS"
36 EnvNoColor = "NO_COLOR"
43 CYellow = "\033[33;1m"
45 CMagenta = "\033[35;1m"
68 flagDebug = flag.Bool("debug", false, "enable debug logging (REDO_DEBUG=1)")
69 flagLogWait = flag.Bool("log-wait", false, "enable wait messages logging (REDO_LOG_WAIT=1)")
70 flagLogLock = flag.Bool("log-lock", false, "enable lock messages logging (REDO_LOG_LOCK=1)")
71 flagLogPid = flag.Bool("log-pid", false, "append PIDs (REDO_LOG_PID=1)")
72 flagLogJS = flag.Bool("log-js", false, "enable jobserver messages logging (REDO_LOG_JS=1)")
75 func trace(level, format string, args ...interface{}) {
78 p = fmt.Sprintf("[%d] ", MyPid)
82 os.Stderr.WriteString(StderrPrefix + p + fmt.Sprintf(format+"\n", args...))
90 if !(LogWait || Debug) {
97 if !(LogLock || Debug) {
102 if !(LogJS || Debug) {
111 msg := fmt.Sprintf(format, args...)
112 msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg)
113 os.Stderr.WriteString(msg + "\n")
116 func colourize(colour, s string) string {
120 return colour + s + CReset