Update logging per feedback I got on a CTL patch set
Change-Id: I0f16ae0e6340478f668823c193b24ff17ea3d9f3
This commit is contained in:
parent
c3a0184f6b
commit
cff2713f74
2
Makefile
2
Makefile
@ -43,7 +43,7 @@ COVER_EXCLUDE ?= (zz_generated)
|
||||
|
||||
# Override the value of the version variable in main.go
|
||||
LD_FLAGS= '-X opendev.org/airship/airshipui/pkg/commands.version=$(GIT_VERSION)'
|
||||
GO_FLAGS := -ldflags=$(LD_FLAGS)
|
||||
GO_FLAGS := -ldflags=$(LD_FLAGS) -trimpath
|
||||
BUILD_DIR := bin
|
||||
|
||||
# Find all main.go files under cmd, excluding airshipui itself
|
||||
|
@ -19,13 +19,9 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const logSep = "airshipui/"
|
||||
|
||||
var (
|
||||
// LogLevel can specify what level the system runs at
|
||||
LogLevel = 6
|
||||
@ -37,7 +33,7 @@ var (
|
||||
2: "ERROR",
|
||||
1: "FATAL",
|
||||
}
|
||||
airshipLog = log.New(os.Stderr, "[airshipui] ", log.LstdFlags)
|
||||
airshipLog = log.New(os.Stderr, "[airshipui] ", log.LstdFlags|log.Llongfile)
|
||||
writeMutex sync.Mutex
|
||||
)
|
||||
|
||||
@ -117,14 +113,13 @@ func Writer() io.Writer {
|
||||
func writeLog(level int, v ...interface{}) {
|
||||
// determine if we need to display the logs
|
||||
if level <= LogLevel {
|
||||
_, file, line, _ := runtime.Caller(2)
|
||||
sa := strings.SplitAfter(file, logSep)
|
||||
if len(sa) == 2 {
|
||||
file = sa[1]
|
||||
}
|
||||
|
||||
writeMutex.Lock()
|
||||
defer writeMutex.Unlock()
|
||||
airshipLog.Printf("[%s] [%s:%d] %v", levels[level], file, line, fmt.Sprint(v...))
|
||||
// the origionall caller of this is 3 steps back, the output will display who called it
|
||||
err := airshipLog.Output(3, fmt.Sprintf("[%s] %v", levels[level], fmt.Sprint(v...)))
|
||||
if err != nil {
|
||||
airshipLog.Print(v...)
|
||||
airshipLog.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"opendev.org/airship/airshipui/pkg/log"
|
||||
)
|
||||
|
||||
var logFormatRegex = regexp.MustCompile(`^\[airshipui\] \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \[.*\] \[.*\] .*`)
|
||||
var logFormatRegex = regexp.MustCompile(`^\[airshipui\] .*`)
|
||||
|
||||
func TestLoggingTrace(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user