fix logging when JSON output selected
parent
0ab2051e24
commit
b9c0b16fc4
|
|
@ -94,6 +94,7 @@ func Step(st style.Enum, format string, a ...V) {
|
|||
outStyled, _ := stylized(st, useColor, format, a...)
|
||||
if JSON {
|
||||
register.PrintStep(outStyled)
|
||||
klog.Info(outStyled)
|
||||
return
|
||||
}
|
||||
register.RecordStep(outStyled)
|
||||
|
|
@ -154,7 +155,6 @@ func Infof(format string, a ...V) {
|
|||
outStyled, _ := stylized(style.Option, useColor, format, a...)
|
||||
if JSON {
|
||||
register.PrintInfo(outStyled)
|
||||
return
|
||||
}
|
||||
String(outStyled)
|
||||
}
|
||||
|
|
@ -163,8 +163,9 @@ func Infof(format string, a ...V) {
|
|||
func String(format string, a ...interface{}) {
|
||||
// Flush log buffer so that output order makes sense
|
||||
klog.Flush()
|
||||
defer klog.Flush()
|
||||
|
||||
if silent {
|
||||
if silent || JSON {
|
||||
klog.Infof(format, a...)
|
||||
return
|
||||
}
|
||||
|
|
@ -212,10 +213,6 @@ func spinnerString(format string, a ...interface{}) {
|
|||
|
||||
// Ln writes a basic formatted string with a newline to stdout
|
||||
func Ln(format string, a ...interface{}) {
|
||||
if JSON {
|
||||
klog.Warningf("please use out.T to log steps in JSON")
|
||||
return
|
||||
}
|
||||
String(format+"\n", a...)
|
||||
}
|
||||
|
||||
|
|
@ -229,6 +226,7 @@ func ErrT(st style.Enum, format string, a ...V) {
|
|||
func Err(format string, a ...interface{}) {
|
||||
if JSON {
|
||||
register.PrintError(format)
|
||||
klog.Warningf(format, a...)
|
||||
return
|
||||
}
|
||||
register.RecordError(format)
|
||||
|
|
@ -271,6 +269,7 @@ func WarningT(format string, a ...V) {
|
|||
}
|
||||
st, _ := stylized(style.Warning, useColor, format, a...)
|
||||
register.PrintWarning(st)
|
||||
klog.Warning(st)
|
||||
return
|
||||
}
|
||||
ErrT(style.Warning, format, a...)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package out
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/pkg/minikube/out/register"
|
||||
"k8s.io/minikube/pkg/minikube/reason"
|
||||
"k8s.io/minikube/pkg/minikube/style"
|
||||
|
|
@ -35,9 +36,8 @@ func Error(k reason.Kind, format string, a ...V) {
|
|||
"url": k.URL,
|
||||
"issues": strings.Join(k.IssueURLs(), ","),
|
||||
})
|
||||
} else {
|
||||
displayText(k, format, a...)
|
||||
}
|
||||
displayText(k, format, a...)
|
||||
}
|
||||
|
||||
// WarnReason shows a warning reason
|
||||
|
|
@ -45,9 +45,8 @@ func WarnReason(k reason.Kind, format string, a ...V) {
|
|||
if JSON {
|
||||
msg := Fmt(format, a...)
|
||||
register.PrintWarning(msg)
|
||||
} else {
|
||||
displayText(k, format, a...)
|
||||
}
|
||||
displayText(k, format, a...)
|
||||
}
|
||||
|
||||
// indentMultiLine indents a message if it contains multiple lines
|
||||
|
|
@ -71,33 +70,42 @@ func displayText(k reason.Kind, format string, a ...V) {
|
|||
st = style.KnownIssue
|
||||
}
|
||||
|
||||
ErrT(st, format, a...)
|
||||
determineOutput(st, format, a...)
|
||||
|
||||
if k.Advice != "" {
|
||||
|
||||
advice := indentMultiLine(Fmt(k.Advice, a...))
|
||||
ErrT(style.Tip, Fmt("Suggestion: {{.advice}}", V{"advice": advice}))
|
||||
determineOutput(style.Tip, Fmt("Suggestion: {{.advice}}", V{"advice": advice}))
|
||||
}
|
||||
|
||||
if k.URL != "" {
|
||||
ErrT(style.Documentation, "Documentation: {{.url}}", V{"url": k.URL})
|
||||
determineOutput(style.Documentation, "Documentation: {{.url}}", V{"url": k.URL})
|
||||
}
|
||||
|
||||
issueURLs := k.IssueURLs()
|
||||
if len(issueURLs) == 1 {
|
||||
ErrT(style.Issues, "Related issue: {{.url}}", V{"url": issueURLs[0]})
|
||||
determineOutput(style.Issues, "Related issue: {{.url}}", V{"url": issueURLs[0]})
|
||||
}
|
||||
|
||||
if len(issueURLs) > 1 {
|
||||
ErrT(style.Issues, "Related issues:")
|
||||
determineOutput(style.Issues, "Related issues:")
|
||||
for _, i := range issueURLs {
|
||||
ErrT(style.Issue, "{{.url}}", V{"url": i})
|
||||
determineOutput(style.Issue, "{{.url}}", V{"url": i})
|
||||
}
|
||||
}
|
||||
|
||||
if k.NewIssueLink {
|
||||
ErrT(style.Empty, "")
|
||||
determineOutput(style.Empty, "")
|
||||
displayGitHubIssueMessage()
|
||||
}
|
||||
Ln("")
|
||||
}
|
||||
|
||||
func determineOutput(st style.Enum, format string, a ...V) {
|
||||
if !JSON {
|
||||
ErrT(st, format, a...)
|
||||
return
|
||||
}
|
||||
errStyled, _ := stylized(st, useColor, format, a...)
|
||||
klog.Warning(errStyled)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue