/* goredo -- redo implementation on pure Go Copyright (C) 2020 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ // Logging facilities package main import ( "fmt" "os" "strings" ) const ( CReset = "\033[0m" CBold = "\033[1m" CBlack = "\033[30;1m" CRed = "\033[31;1m" CGreen = "\033[32;1m" CYellow = "\033[33;1m" CBlue = "\033[34;1m" CMagenta = "\033[35;1m" CCyan = "\033[36;1m" CWhite = "\033[37;1m" CDebug = CYellow CRedo = CGreen CWait = CBlue CLock = CCyan CErr = CRed CWarn = CMagenta CJS = CWhite CNone = "NONE" ) var ( NoColor bool Debug bool LogWait bool LogLock bool LogJS bool MyPid int ) func trace(level, format string, args ...interface{}) { var p string if MyPid != 0 { p = fmt.Sprintf("[%d] ", MyPid) } switch level { case CNone: os.Stderr.WriteString(StderrPrefix + p + fmt.Sprintf(format+"\n", args...)) return case CDebug: if !Debug { return } p += "dbg " case CWait: if !(LogWait || Debug) { return } p += "wait " case CRedo: p += "redo " case CLock: if !(LogLock || Debug) { return } p += "lock " case CJS: if !(LogJS || Debug) { return } p += "js " case CErr: p += "err " case CWarn: p += "warn " } msg := fmt.Sprintf(format, args...) msg = StderrPrefix + colourize(level, p+strings.Repeat(". ", Level)+msg) os.Stderr.WriteString(msg + "\n") } func colourize(colour, s string) string { if NoColor { return s } return colour + s + CReset }