more func add

master
兔子 3 years ago
parent 0e91e97132
commit 16ae4fae3d

@ -35,7 +35,7 @@ func generateCoreLogStr(skip int, logstr string) string {
return logStr return logStr
} }
func (logger *starlog) build(thread string, isStd bool, handler func([]Attr, string), level int, logDetail string) { func (logger *starlog) build(thread string, isStd bool, isShow bool, handler func([]Attr, string), level int, logDetail string) {
logger.mu.Lock() logger.mu.Lock()
defer logger.mu.Unlock() defer logger.mu.Unlock()
var skip, line int = 3, 0 var skip, line int = 3, 0
@ -60,25 +60,32 @@ func (logger *starlog) build(thread string, isStd bool, handler func([]Attr, str
h, i, s := now.Clock() h, i, s := now.Clock()
micro := now.Nanosecond() / 1e3 micro := now.Nanosecond() / 1e3
logStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d.%06d", y, m, d, h, i, s, micro) logStr := fmt.Sprintf("%04d-%02d-%02d %02d:%02d:%02d.%06d", y, m, d, h, i, s, micro)
var cenStr string
if logger.showDeatilFile { if logger.showDeatilFile {
logStr += " " + fileName + ":" + strconv.Itoa(line) cenStr += " " + fileName + ":" + strconv.Itoa(line)
} }
if logger.showFuncName { if logger.showFuncName {
logStr += " <" + funcname + ">" cenStr += " <" + funcname + ">"
} }
if logger.showThread { if logger.showThread {
logStr += " |" + thread + "|" cenStr += " |" + thread + "|"
} }
if logger.showLevel { if logger.showLevel {
logStr += " " + `[` + levels[level] + `]` cenStr += " " + `[` + levels[level] + `]`
} }
logStr += " " + logDetail if !logger.showColor || !logger.onlyColorLevel {
if logger.showStd { logStr += cenStr + " " + logDetail
} else {
logStr += logger.colorMe[level].Sprint(cenStr) + " " + logDetail
}
if isShow {
if !logger.showColor { if !logger.showColor {
fmt.Print(logStr) fmt.Print(logStr)
} else { } else if !logger.onlyColorLevel {
//logcolor := NewColor(logger.colorList[level]...) //logcolor := NewColor(logger.colorList[level]...)
logger.colorMe[level].Fprint(stdScreen, logStr) logger.colorMe[level].Fprint(stdScreen, logStr)
} else {
fmt.Fprint(stdScreen, logStr)
} }
} }
if handler != nil { if handler != nil {
@ -125,150 +132,165 @@ func (logger *starlog) println(str ...interface{}) string {
func (logger *starlog) Debug(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Debug(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvDebug, strs) logger.build(thread, isStd, true, handler, LvDebug, strs)
} }
func (logger *starlog) Debugf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Debugf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvDebug, strs) logger.build(thread, isStd, true, handler, LvDebug, strs)
} }
func (logger *starlog) Debugln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Debugln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvDebug, strs) logger.build(thread, isStd, true, handler, LvDebug, strs)
} }
func (logger *starlog) Info(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Info(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvInfo, strs) logger.build(thread, isStd, true, handler, LvInfo, strs)
} }
func (logger *starlog) Infof(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Infof(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvInfo, strs) logger.build(thread, isStd, true, handler, LvInfo, strs)
} }
func (logger *starlog) Infoln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Infoln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvInfo, strs) logger.build(thread, isStd, true, handler, LvInfo, strs)
} }
func (logger *starlog) Notice(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Notice(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvNotice, strs) logger.build(thread, isStd, true, handler, LvNotice, strs)
} }
func (logger *starlog) Noticef(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Noticef(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvNotice, strs) logger.build(thread, isStd, true, handler, LvNotice, strs)
} }
func (logger *starlog) Noticeln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Noticeln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvNotice, strs) logger.build(thread, isStd, true, handler, LvNotice, strs)
} }
func (logger *starlog) Warning(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Warning(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvWarning, strs) logger.build(thread, isStd, true, handler, LvWarning, strs)
} }
func (logger *starlog) Warningf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Warningf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvWarning, strs) logger.build(thread, isStd, true, handler, LvWarning, strs)
} }
func (logger *starlog) Warningln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Warningln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvWarning, strs) logger.build(thread, isStd, true, handler, LvWarning, strs)
} }
func (logger *starlog) Error(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Error(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvError, strs) logger.build(thread, isStd, true, handler, LvError, strs)
} }
func (logger *starlog) Errorf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Errorf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvError, strs) logger.build(thread, isStd, true, handler, LvError, strs)
} }
func (logger *starlog) Errorln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Errorln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvError, strs) logger.build(thread, isStd, true, handler, LvError, strs)
} }
func (logger *starlog) Critical(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Critical(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvCritical, strs) logger.build(thread, isStd, true, handler, LvCritical, strs)
} }
func (logger *starlog) Criticalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Criticalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvCritical, strs) logger.build(thread, isStd, true, handler, LvCritical, strs)
} }
func (logger *starlog) Criticalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Criticalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvCritical, strs) logger.build(thread, isStd, true, handler, LvCritical, strs)
} }
func (logger *starlog) Fatal(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Fatal(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvFatal, strs) logger.build(thread, isStd, true, handler, LvFatal, strs)
os.Exit(9) os.Exit(9)
} }
func (logger *starlog) Fatalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Fatalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvFatal, strs) logger.build(thread, isStd, true, handler, LvFatal, strs)
os.Exit(9) os.Exit(9)
} }
func (logger *starlog) Fatalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Fatalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvFatal, strs) logger.build(thread, isStd, true, handler, LvFatal, strs)
os.Exit(9) os.Exit(9)
} }
func (logger *starlog) Panic(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Panic(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, handler, LvPanic, strs) logger.build(thread, isStd, true, handler, LvPanic, strs)
panic(str) panic(str)
} }
func (logger *starlog) Panicf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Panicf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, handler, LvPanic, strs) logger.build(thread, isStd, true, handler, LvPanic, strs)
panic(fmt.Sprintf(format, str...)) panic(fmt.Sprintf(format, str...))
} }
func (logger *starlog) Panicln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Panicln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, handler, LvPanic, strs) logger.build(thread, isStd, true, handler, LvPanic, strs)
panic(fmt.Sprintln(str...)) panic(fmt.Sprintln(str...))
} }
func (logger *starlog) Print(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
if logger.showStd { if isShow {
fmt.Print(strs) fmt.Print(strs)
} }
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Printf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
if logger.showStd { if isShow {
fmt.Print(strs) fmt.Print(strs)
} }
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Println(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
if logger.showStd { if isShow {
fmt.Print(strs) fmt.Print(strs)
} }
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Log(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprint(str...)
logger.build(thread, isStd, isShow, handler, level, strs)
}
func (logger *starlog) Logf(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, isShow, handler, level, strs)
}
func (logger *starlog) Logln(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), str ...interface{}) {
strs := fmt.Sprintln(str...)
logger.build(thread, isStd, isShow, handler, level, strs)
}

@ -214,6 +214,30 @@ func Println(str ...interface{}) {
Std.Println(str...) Std.Println(str...)
} }
func Log(isShow bool, level int, str ...interface{}) {
stdmu.Lock()
defer stdmu.Unlock()
Std.isStd = true
Std.Log(isShow, level, str...)
Std.isStd = false
}
func Logf(isShow bool, level int, format string, str ...interface{}) {
stdmu.Lock()
defer stdmu.Unlock()
Std.isStd = true
Std.Logf(isShow, level, format, str...)
Std.isStd = false
}
func Logln(isShow bool, level int, str ...interface{}) {
stdmu.Lock()
defer stdmu.Unlock()
Std.isStd = true
Std.Logln(isShow, level, str...)
Std.isStd = false
}
func StdPrint(attr []Attr, str ...interface{}) { func StdPrint(attr []Attr, str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
NewColor(attr...).Fprint(stdScreen, strs) NewColor(attr...).Fprint(stdScreen, strs)

@ -38,6 +38,13 @@ func (logger *StarLogger) SetSwitching(sw bool) {
logger.logcore.switching = sw logger.logcore.switching = sw
} }
func (logger *StarLogger) SetOnlyColorLevel(ocl bool) {
logger.logcore.onlyColorLevel = ocl
}
func (logger *StarLogger) GetOnlyColorLevel() bool {
return logger.logcore.onlyColorLevel
}
func (logger *StarLogger) SetShowOriginFile(val bool) { func (logger *StarLogger) SetShowOriginFile(val bool) {
logger.logcore.showDeatilFile = val logger.logcore.showDeatilFile = val
} }
@ -175,13 +182,25 @@ func (logger *StarLogger) Fatalln(str ...interface{}) {
} }
func (logger *StarLogger) Print(str ...interface{}) { func (logger *StarLogger) Print(str ...interface{}) {
logger.logcore.Print(logger.thread, logger.isStd, logger.handlerFunc, str...) logger.logcore.Print(logger.thread, logger.isStd, logger.GetShowStd(), logger.handlerFunc, str...)
} }
func (logger *StarLogger) Printf(format string, str ...interface{}) { func (logger *StarLogger) Printf(format string, str ...interface{}) {
logger.logcore.Printf(logger.thread, logger.isStd, logger.handlerFunc, format, str...) logger.logcore.Printf(logger.thread, logger.isStd, logger.GetShowStd(), logger.handlerFunc, format, str...)
} }
func (logger *StarLogger) Println(str ...interface{}) { func (logger *StarLogger) Println(str ...interface{}) {
logger.logcore.Println(logger.thread, logger.isStd, logger.handlerFunc, str...) logger.logcore.Println(logger.thread, logger.isStd, logger.GetShowStd(), logger.handlerFunc, str...)
}
func (logger *StarLogger) Log(showLog bool, level int, str ...interface{}) {
logger.logcore.Log(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...)
}
func (logger *StarLogger) Logf(showLog bool, level int, format string, str ...interface{}) {
logger.logcore.Logf(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, format, str...)
}
func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{}) {
logger.logcore.Logln(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...)
} }

@ -49,6 +49,7 @@ type starlog struct {
showColor bool showColor bool
switching bool switching bool
showStd bool showStd bool
onlyColorLevel bool
stopWriter bool stopWriter bool
id string id string

Loading…
Cancel
Save