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/>.
31 EnvLevel = "REDO_LEVEL"
32 EnvDebug = "REDO_DEBUG"
33 EnvLogWait = "REDO_LOG_WAIT"
34 EnvLogLock = "REDO_LOG_LOCK"
35 EnvLogPid = "REDO_LOG_PID"
36 EnvLogJS = "REDO_LOG_JS"
37 EnvNoColor = "NO_COLOR"
44 CYellow = "\033[33;1m"
46 CMagenta = "\033[35;1m"
69 flagDebug = flag.Bool("debug", false, fmt.Sprintf("enable debug logging (%s=1)", EnvDebug))
70 flagLogWait = flag.Bool("log-wait", false, fmt.Sprintf("enable wait messages logging (%s=1)", EnvLogWait))
71 flagLogLock = flag.Bool("log-lock", false, fmt.Sprintf("enable lock messages logging (%s=1)", EnvLogLock))
72 flagLogPid = flag.Bool("log-pid", false, fmt.Sprintf("append PIDs (%s=1)", EnvLogPid))
73 flagLogJS = flag.Bool("log-js", false, fmt.Sprintf("enable jobserver messages logging (%s=1)", EnvLogJS))
78 func trace(level, format string, args ...interface{}) {
81 p = fmt.Sprintf("[%d] ", MyPid)
86 os.Stderr.WriteString(StderrPrefix + p + fmt.Sprintf(format+"\n", args...))
95 if !(LogWait || Debug) {
102 if !(LogLock || Debug) {
107 if !(LogJS || Debug) {
116 msg := fmt.Sprintf(format, args...)
117 msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg)
119 os.Stderr.WriteString(msg + "\n")
123 func colourize(colour, s string) string {
127 return colour + s + CReset