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))
79 func fillUpToTermSize(s, end string) string {
81 if sLen < LogLenPrev {
82 s += strings.Repeat(" ", LogLenPrev-sLen)
90 func trace(level, format string, args ...interface{}) {
93 p = fmt.Sprintf("[%d] ", MyPid)
98 os.Stderr.WriteString(fillUpToTermSize(
99 StderrPrefix+p+fmt.Sprintf(format, args...), "\n",
109 if !(LogWait || Debug) {
116 if !(LogLock || Debug) {
121 if !(LogJS || Debug) {
130 msg := fmt.Sprintf(format, args...)
131 msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg)
133 os.Stderr.WriteString(fillUpToTermSize(msg, "\n"))
137 func colourize(colour, s string) string {
141 return colour + s + CReset