forked from mirror/logrus
Rewrite if-else-if-else to switch statements
This commit is contained in:
parent
dae0fa8d5b
commit
1487633cc3
|
@ -95,11 +95,10 @@ func (f *TextFormatter) isColored() bool {
|
||||||
isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows"))
|
isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows"))
|
||||||
|
|
||||||
if f.EnvironmentOverrideColors {
|
if f.EnvironmentOverrideColors {
|
||||||
if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" {
|
switch force, ok := os.LookupEnv("CLICOLOR_FORCE"); {
|
||||||
|
case ok && force != "0":
|
||||||
isColored = true
|
isColored = true
|
||||||
} else if ok && force == "0" {
|
case ok && force == "0", os.Getenv("CLICOLOR") == "0":
|
||||||
isColored = false
|
|
||||||
} else if os.Getenv("CLICOLOR") == "0" {
|
|
||||||
isColored = false
|
isColored = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,11 +235,12 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
|
||||||
caller = fileVal + " " + funcVal
|
caller = fileVal + " " + funcVal
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.DisableTimestamp {
|
switch {
|
||||||
|
case f.DisableTimestamp:
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message)
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message)
|
||||||
} else if !f.FullTimestamp {
|
case !f.FullTimestamp:
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message)
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message)
|
||||||
} else {
|
default:
|
||||||
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message)
|
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message)
|
||||||
}
|
}
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
|
|
Loading…
Reference in New Issue