Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tlogger: print log type #4774

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions internal/grpctest/tlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,23 @@ const callingFrame = 4

type logType int

func (l logType) String() string {
switch l {
case infoLog:
return "INFO"
case warningLog:
return "WARNING"
case errorLog:
return "ERROR"
case fatalLog:
return "FATAL"
}
return "UNKNOWN"
}

const (
logLog logType = iota
infoLog logType = iota
warningLog
errorLog
fatalLog
)
Expand Down Expand Up @@ -83,7 +98,7 @@ func (g *tLogger) log(ltype logType, depth int, format string, args ...interface
g.t.Error(err)
return
}
args = append([]interface{}{prefix}, args...)
args = append([]interface{}{ltype.String() + " " + prefix}, args...)
args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(g.start)))

if format == "" {
Expand Down Expand Up @@ -180,35 +195,35 @@ func (g *tLogger) expected(s string) bool {
}

func (g *tLogger) Info(args ...interface{}) {
g.log(logLog, 0, "", args...)
g.log(infoLog, 0, "", args...)
}

func (g *tLogger) Infoln(args ...interface{}) {
g.log(logLog, 0, "", args...)
g.log(infoLog, 0, "", args...)
}

func (g *tLogger) Infof(format string, args ...interface{}) {
g.log(logLog, 0, format, args...)
g.log(infoLog, 0, format, args...)
}

func (g *tLogger) InfoDepth(depth int, args ...interface{}) {
g.log(logLog, depth, "", args...)
g.log(infoLog, depth, "", args...)
}

func (g *tLogger) Warning(args ...interface{}) {
g.log(logLog, 0, "", args...)
g.log(warningLog, 0, "", args...)
}

func (g *tLogger) Warningln(args ...interface{}) {
g.log(logLog, 0, "", args...)
g.log(warningLog, 0, "", args...)
}

func (g *tLogger) Warningf(format string, args ...interface{}) {
g.log(logLog, 0, format, args...)
g.log(warningLog, 0, format, args...)
}

func (g *tLogger) WarningDepth(depth int, args ...interface{}) {
g.log(logLog, depth, "", args...)
g.log(warningLog, depth, "", args...)
}

func (g *tLogger) Error(args ...interface{}) {
Expand Down