pull/1/head
兔子 5 years ago
parent 4f2eb0c238
commit 3f68382587

@ -56,9 +56,10 @@ var (
LvPanic: []color.Attribute{RED, BOLD}, LvPanic: []color.Attribute{RED, BOLD},
LvFatal: []color.Attribute{RED}, LvFatal: []color.Attribute{RED},
} }
LogLevel int = 0 LogLevel int = 0
ShowLine, ShowLevel, DoWrite, switching bool = true, true, true, false ShowLine, ShowLevel, DoWrite, DoShow, switching bool = true, true, true, true, false
loghandle *os.File = nil loghandle *os.File = nil
HandleFunc func([]color.Attribute, string)
) )
func write(logs string) { func write(logs string) {
@ -71,7 +72,7 @@ func write(logs string) {
loghandle.WriteString(logs) loghandle.WriteString(logs)
} }
func output(level int, showline, showlv, dowrite bool, strlog string) { func output(level int, showline, showlv, dowrite, doshow bool, strlog string) {
var logs string var logs string
if level < LogLevel { if level < LogLevel {
return return
@ -88,11 +89,16 @@ func output(level int, showline, showlv, dowrite bool, strlog string) {
} else { } else {
logs = fmt.Sprintf("%s %s", date, strlog) logs = fmt.Sprintf("%s %s", date, strlog)
} }
for _, v := range Colors[level] { if doshow {
color.Set(v) for _, v := range Colors[level] {
color.Set(v)
}
fmt.Print(logs)
color.Set(color.Reset)
}
if HandleFunc != nil {
go HandleFunc(Colors[level], logs)
} }
fmt.Print(logs)
color.Set(color.Reset)
if dowrite { if dowrite {
go write(logs) go write(logs)
} }
@ -148,130 +154,130 @@ func Println(c1, c2 color.Attribute, str ...interface{}) {
func Debug(str ...interface{}) { func Debug(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvDebug, ShowLine, ShowLevel, DoWrite, strs) output(LvDebug, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Debugf(format string, str ...interface{}) { func Debugf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvDebug, ShowLine, ShowLevel, DoWrite, strs) output(LvDebug, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Debugln(str ...interface{}) { func Debugln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvDebug, ShowLine, ShowLevel, DoWrite, strs) output(LvDebug, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Info(str ...interface{}) { func Info(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvInfo, ShowLine, ShowLevel, DoWrite, strs) output(LvInfo, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Infof(format string, str ...interface{}) { func Infof(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvInfo, ShowLine, ShowLevel, DoWrite, strs) output(LvInfo, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Infoln(str ...interface{}) { func Infoln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvInfo, ShowLine, ShowLevel, DoWrite, strs) output(LvInfo, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Notice(str ...interface{}) { func Notice(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvNotice, ShowLine, ShowLevel, DoWrite, strs) output(LvNotice, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Noticef(format string, str ...interface{}) { func Noticef(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvNotice, ShowLine, ShowLevel, DoWrite, strs) output(LvNotice, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Noticeln(str ...interface{}) { func Noticeln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvNotice, ShowLine, ShowLevel, DoWrite, strs) output(LvNotice, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Warning(str ...interface{}) { func Warning(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvWarning, ShowLine, ShowLevel, DoWrite, strs) output(LvWarning, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Warningf(format string, str ...interface{}) { func Warningf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvWarning, ShowLine, ShowLevel, DoWrite, strs) output(LvWarning, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Warningln(str ...interface{}) { func Warningln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvWarning, ShowLine, ShowLevel, DoWrite, strs) output(LvWarning, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Error(str ...interface{}) { func Error(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvError, ShowLine, ShowLevel, DoWrite, strs) output(LvError, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Errorf(format string, str ...interface{}) { func Errorf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvError, ShowLine, ShowLevel, DoWrite, strs) output(LvError, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Errorln(str ...interface{}) { func Errorln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvError, ShowLine, ShowLevel, DoWrite, strs) output(LvError, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Critical(str ...interface{}) { func Critical(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvCritical, ShowLine, ShowLevel, DoWrite, strs) output(LvCritical, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Criticalf(format string, str ...interface{}) { func Criticalf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvCritical, ShowLine, ShowLevel, DoWrite, strs) output(LvCritical, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Criticalln(str ...interface{}) { func Criticalln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvCritical, ShowLine, ShowLevel, DoWrite, strs) output(LvCritical, ShowLine, ShowLevel, DoWrite, DoShow, strs)
} }
func Fatal(str ...interface{}) { func Fatal(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvFatal, ShowLine, ShowLevel, DoWrite, strs) output(LvFatal, ShowLine, ShowLevel, DoWrite, DoShow, strs)
CloseLog() CloseLog()
os.Exit(9) os.Exit(9)
} }
func Fatalf(format string, str ...interface{}) { func Fatalf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvFatal, ShowLine, ShowLevel, DoWrite, strs) output(LvFatal, ShowLine, ShowLevel, DoWrite, DoShow, strs)
CloseLog() CloseLog()
os.Exit(9) os.Exit(9)
} }
func Fatalln(str ...interface{}) { func Fatalln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvFatal, ShowLine, ShowLevel, DoWrite, strs) output(LvFatal, ShowLine, ShowLevel, DoWrite, DoShow, strs)
CloseLog() CloseLog()
os.Exit(9) os.Exit(9)
} }
func Panic(str ...interface{}) { func Panic(str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
output(LvPanic, ShowLine, ShowLevel, DoWrite, strs) output(LvPanic, ShowLine, ShowLevel, DoWrite, DoShow, strs)
panic(str) panic(str)
} }
func Panicf(format string, str ...interface{}) { func Panicf(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
output(LvPanic, ShowLine, ShowLevel, DoWrite, strs) output(LvPanic, ShowLine, ShowLevel, DoWrite, DoShow, strs)
panic(strs) panic(strs)
} }
func Panicln(str ...interface{}) { func Panicln(str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
output(LvPanic, ShowLine, ShowLevel, DoWrite, strs) output(LvPanic, ShowLine, ShowLevel, DoWrite, DoShow, strs)
panic(str) panic(str)
} }

Loading…
Cancel
Save