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

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

Loading…
Cancel
Save