change LvNotice Default Color and Add Name Prop For log

master
兔子 2 years ago
parent a003137225
commit eac80f6d2b
Signed by: b612
GPG Key ID: 481225A74DEB62A1

@ -35,7 +35,7 @@ func generateCoreLogStr(skip int, logstr string) string {
return logStr return logStr
} }
func (logger *starlog) build(thread string, isStd bool, isShow bool, handler func([]Attr, string), level int, logDetail string) { func (logger *starlog) build(thread string, isStd bool, isShow bool, handler func(data LogData), 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
@ -91,8 +91,11 @@ func (logger *starlog) build(thread string, isStd bool, isShow bool, handler fun
if handler != nil { if handler != nil {
stacks.Push(logTransfer{ stacks.Push(logTransfer{
handlerFunc: handler, handlerFunc: handler,
colors: logger.colorList[level], LogData: LogData{
logStr: logStr, Log: logStr,
Colors: logger.colorList[level],
Name: logger.name,
},
}) })
} }
if !logger.stopWriter { if !logger.stopWriter {
@ -130,133 +133,133 @@ func (logger *starlog) println(str ...interface{}) string {
return fmt.Sprintln(str...) return fmt.Sprintln(str...)
} }
func (logger *starlog) Debug(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Debug(thread string, isStd bool, handler func(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvError, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvError, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvError, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs) logger.build(thread, isStd, logger.showStd, 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(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs) logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
panic(fmt.Sprintln(str...)) panic(fmt.Sprintln(str...))
} }
func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler func(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
if isShow { if isShow {
fmt.Print(strs) fmt.Print(strs)
@ -264,7 +267,7 @@ func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler fun
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler func([]Attr, string), format string, str ...interface{}) { func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler func(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
if isShow { if isShow {
fmt.Print(strs) fmt.Print(strs)
@ -272,7 +275,7 @@ func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler fu
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler func(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
if isShow { if isShow {
fmt.Print(strs) fmt.Print(strs)
@ -280,17 +283,32 @@ func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler f
logger.write(strs) logger.write(strs)
} }
func (logger *starlog) Log(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), str ...interface{}) { func (logger *starlog) Log(thread string, isStd bool, isShow bool, level int, handler func(LogData), str ...interface{}) {
strs := fmt.Sprint(str...) strs := fmt.Sprint(str...)
logger.build(thread, isStd, isShow, handler, level, strs) 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{}) { func (logger *starlog) Logf(thread string, isStd bool, isShow bool, level int, handler func(LogData), format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...) strs := fmt.Sprintf(format, str...)
logger.build(thread, isStd, isShow, handler, level, strs) 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{}) { func (logger *starlog) Logln(thread string, isStd bool, isShow bool, level int, handler func(LogData), str ...interface{}) {
strs := fmt.Sprintln(str...) strs := fmt.Sprintln(str...)
logger.build(thread, isStd, isShow, handler, level, strs) logger.build(thread, isStd, isShow, handler, level, strs)
} }
func (logger *starlog) Write(str ...interface{}) {
strs := fmt.Sprint(str...)
logger.Write(strs)
}
func (logger *starlog) Writef(format string, str ...interface{}) {
strs := fmt.Sprintf(format, str...)
logger.Write(strs)
}
func (logger *starlog) Writeln(str ...interface{}) {
strs := fmt.Sprintln(str...)
logger.Write(strs)
}

@ -1,10 +1,20 @@
module b612.me/starlog module b612.me/starlog
go 1.16 go 1.18
require (
b612.me/starmap v1.2.1
b612.me/staros v1.1.4
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c
)
require ( require (
b612.me/notify v1.2.0 // indirect b612.me/notify v1.2.0 // indirect
b612.me/starmap v1.2.0 b612.me/starcrypto v0.0.1 // indirect
b612.me/staros v1.1.2 b612.me/stario v0.0.7 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 b612.me/starnet v0.1.3 // indirect
b612.me/win32api v0.0.1 // indirect
b612.me/wincmd v0.0.1 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
) )

@ -2,27 +2,32 @@ b612.me/notify v1.2.0 h1:RedXNMLqY+TozalmdIUM27EFvZp06pzeqHn/F9G1eEs=
b612.me/notify v1.2.0/go.mod h1:EPctpKCVnoZO1hUJTRYpOw3huTemua+SGNIuUCsnzOc= b612.me/notify v1.2.0/go.mod h1:EPctpKCVnoZO1hUJTRYpOw3huTemua+SGNIuUCsnzOc=
b612.me/starcrypto v0.0.1 h1:xGngzXPUrVbqtWzNw2e+0eWsdG7GG1/X+ONDGIzdriI= b612.me/starcrypto v0.0.1 h1:xGngzXPUrVbqtWzNw2e+0eWsdG7GG1/X+ONDGIzdriI=
b612.me/starcrypto v0.0.1/go.mod h1:hz0xRnfWNpYOlVrIPoGrQOWPibq4YiUZ7qN5tsQbzPo= b612.me/starcrypto v0.0.1/go.mod h1:hz0xRnfWNpYOlVrIPoGrQOWPibq4YiUZ7qN5tsQbzPo=
b612.me/stario v0.0.5 h1:Q1OGF+8eOoK49zMzkyh80GWaMuknhey6+PWJJL9ZuNo=
b612.me/stario v0.0.5/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw= b612.me/stario v0.0.5/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw=
b612.me/starmap v1.2.0 h1:sRUeMRUqOyb3pAQln5U6V07kIYp0714Z3gJ/g2nCJXc= b612.me/stario v0.0.7 h1:QbQcsHCVLE6vRgVrPN4+9DGiSaC6IWdtm4ClL2tpMUg=
b612.me/starmap v1.2.0/go.mod h1:InIJXA3qVeMkvkUhCV/XPchCiNcJcVYdYV8EAOGbGZY= b612.me/stario v0.0.7/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw=
b612.me/starmap v1.2.1 h1:fil0pyjYGZrioB0OJx+qhmJjrl+PooGEmfRI3yOm/fY=
b612.me/starmap v1.2.1/go.mod h1:m3m0CkkXqlel1FBBJVZ8ViIFfeWAej91BTemGfGSJLQ=
b612.me/starnet v0.1.3 h1:UjY6M96gdPdJtxnQGzCttqSwFw93sDZSHiIGtdOlFfk= b612.me/starnet v0.1.3 h1:UjY6M96gdPdJtxnQGzCttqSwFw93sDZSHiIGtdOlFfk=
b612.me/starnet v0.1.3/go.mod h1:j/dd6BKwQK80O4gfbGYg2aYtPH76gSdgpuKboK/DwN4= b612.me/starnet v0.1.3/go.mod h1:j/dd6BKwQK80O4gfbGYg2aYtPH76gSdgpuKboK/DwN4=
b612.me/staros v1.1.2 h1:jBFU1KHgn0VpyitYKwC9Zwj1GjmDBGM+fuTyV0yGXRo= b612.me/staros v1.1.4 h1:Ikh74tYMqXkDHXJHArVf1/yhLMORfwZ+q8clAKvYjrM=
b612.me/staros v1.1.2/go.mod h1:9kNWVJWNJfs2MiWEt7X3SO+ixYKPGqus1ShTy8hpfU0= b612.me/staros v1.1.4/go.mod h1://P/Ivz7hb/lrI+FwMh5G/T27iJ8WlWZZr3wOoPfVsU=
b612.me/win32api v0.0.1 h1:vLFB1xhO6pd9+zB2EyaapKB459Urv3v+C1YwgwOFEWo= b612.me/win32api v0.0.1 h1:vLFB1xhO6pd9+zB2EyaapKB459Urv3v+C1YwgwOFEWo=
b612.me/win32api v0.0.1/go.mod h1:MHu0JBQjzxQ2yxpZPUBbn5un45o67eF5iWKa4Q9e0yE= b612.me/win32api v0.0.1/go.mod h1:MHu0JBQjzxQ2yxpZPUBbn5un45o67eF5iWKa4Q9e0yE=
b612.me/wincmd v0.0.1 h1:4+RCFKHuD/JqAYsdtO6sTNKJs1nQVMQo87h6KhTJjkM= b612.me/wincmd v0.0.1 h1:4+RCFKHuD/JqAYsdtO6sTNKJs1nQVMQo87h6KhTJjkM=
b612.me/wincmd v0.0.1/go.mod h1:32xTM7qWAI7jx6qwTrig05rxejSYbSp7CX5WD7qsMxY= b612.me/wincmd v0.0.1/go.mod h1:32xTM7qWAI7jx6qwTrig05rxejSYbSp7CX5WD7qsMxY=
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000 h1:SL+8VVnkqyshUSz5iNnXtrBQzvFF2SkROm6t5RczFAE=
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

@ -262,10 +262,10 @@ func GetWriter() io.Writer {
return Std.GetWriter() return Std.GetWriter()
} }
func SetHandler(f func([]Attr, string)) { func SetHandler(f func(LogData)) {
Std.SetHandler(f) Std.SetHandler(f)
} }
func GetHandler() func([]Attr, string) { func GetHandler() func(LogData) {
return Std.GetHandler() return Std.GetHandler()
} }
func SetSwitching(sw bool) { func SetSwitching(sw bool) {

@ -28,10 +28,10 @@ func (logger *StarLogger) GetWriter() io.Writer {
return logger.logcore.output return logger.logcore.output
} }
func (logger *StarLogger) SetHandler(f func([]Attr, string)) { func (logger *StarLogger) SetHandler(f func(LogData)) {
logger.handlerFunc = f logger.handlerFunc = f
} }
func (logger *StarLogger) GetHandler() func([]Attr, string) { func (logger *StarLogger) GetHandler() func(LogData) {
return logger.handlerFunc return logger.handlerFunc
} }
func (logger *StarLogger) SetSwitching(sw bool) { func (logger *StarLogger) SetSwitching(sw bool) {
@ -204,3 +204,15 @@ func (logger *StarLogger) Logf(showLog bool, level int, format string, str ...in
func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{}) { func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{}) {
logger.logcore.Logln(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...) logger.logcore.Logln(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...)
} }
func (logger *StarLogger) Write(str ...interface{}) {
logger.logcore.Write(str...)
}
func (logger *StarLogger) Writef(format string, str ...interface{}) {
logger.logcore.Writef(format, str...)
}
func (logger *StarLogger) Writeln(str ...interface{}) {
logger.logcore.Writeln(str...)
}

@ -53,22 +53,27 @@ type starlog struct {
onlyColorLevel bool onlyColorLevel bool
stopWriter bool stopWriter bool
id string id string
name string
colorList map[int][]Attr colorList map[int][]Attr
colorMe map[int]*Color colorMe map[int]*Color
} }
type StarLogger struct { type StarLogger struct {
thread string thread string
handlerFunc func([]Attr, string) handlerFunc func(LogData)
logcore *starlog logcore *starlog
isStd bool isStd bool
} }
type logTransfer struct { type logTransfer struct {
handlerFunc func([]Attr, string) handlerFunc func(LogData)
colors []Attr LogData
logStr string }
type LogData struct {
Name string
Log string
Colors []Attr
} }
func newLogCore(out io.Writer) *starlog { func newLogCore(out io.Writer) *starlog {
@ -87,7 +92,7 @@ func newLogCore(out io.Writer) *starlog {
colorList: map[int][]Attr{ colorList: map[int][]Attr{
LvDebug: []Attr{FgWhite}, LvDebug: []Attr{FgWhite},
LvInfo: []Attr{FgGreen}, LvInfo: []Attr{FgGreen},
LvNotice: []Attr{FgBlue}, LvNotice: []Attr{FgCyan},
LvWarning: []Attr{FgYellow}, LvWarning: []Attr{FgYellow},
LvError: []Attr{FgMagenta}, LvError: []Attr{FgMagenta},
LvCritical: []Attr{FgRed, Bold}, LvCritical: []Attr{FgRed, Bold},
@ -97,7 +102,7 @@ func newLogCore(out io.Writer) *starlog {
colorMe: map[int]*Color{ colorMe: map[int]*Color{
LvDebug: NewColor([]Attr{FgWhite}...), LvDebug: NewColor([]Attr{FgWhite}...),
LvInfo: NewColor([]Attr{FgGreen}...), LvInfo: NewColor([]Attr{FgGreen}...),
LvNotice: NewColor([]Attr{FgBlue}...), LvNotice: NewColor([]Attr{FgCyan}...),
LvWarning: NewColor([]Attr{FgYellow}...), LvWarning: NewColor([]Attr{FgYellow}...),
LvError: NewColor([]Attr{FgMagenta}...), LvError: NewColor([]Attr{FgMagenta}...),
LvCritical: NewColor([]Attr{FgRed, Bold}...), LvCritical: NewColor([]Attr{FgRed, Bold}...),
@ -128,6 +133,16 @@ func (logger *StarLogger) SetNewRandomFlag() {
logger.thread = getRandomFlag(false) logger.thread = getRandomFlag(false)
} }
func (logger *StarLogger) SetName(name string) {
logger.logcore.mu.Lock()
defer logger.logcore.mu.Unlock()
logger.logcore.name = name
}
func (logger *StarLogger) GetName() string {
return logger.logcore.name
}
func getRandomFlag(isMain bool) string { func getRandomFlag(isMain bool) string {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
if isMain { if isMain {
@ -170,7 +185,7 @@ func StartStacks() {
} }
val := poped.(logTransfer) val := poped.(logTransfer)
if val.handlerFunc != nil { if val.handlerFunc != nil {
val.handlerFunc(val.colors, val.logStr) val.handlerFunc(val.LogData)
} }
} }
}() }()

Loading…
Cancel
Save