fixed: make log api unblocked

This commit is contained in:
lelemka0
2022-05-06 11:43:53 +08:00
committed by Meta
parent 463101aec1
commit 9e9c3c810f
2 changed files with 19 additions and 15 deletions

View File

@ -10,8 +10,8 @@ import (
)
var (
logCh = make(chan *Event)
source = observable.NewObservable[*Event](logCh)
logCh = make(chan Event)
source = observable.NewObservable[Event](logCh)
level = INFO
)
@ -57,12 +57,12 @@ func Fatalln(format string, v ...any) {
log.Fatalf(format, v...)
}
func Subscribe() observable.Subscription[*Event] {
func Subscribe() observable.Subscription[Event] {
sub, _ := source.Subscribe()
return sub
}
func UnSubscribe(sub observable.Subscription[*Event]) {
func UnSubscribe(sub observable.Subscription[Event]) {
source.UnSubscribe(sub)
}
@ -74,7 +74,7 @@ func SetLevel(newLevel LogLevel) {
level = newLevel
}
func print(data *Event) {
func print(data Event) {
if data.LogLevel < level {
return
}
@ -91,15 +91,9 @@ func print(data *Event) {
}
}
func newLog(logLevel LogLevel, format string, v ...any) *Event {
return &Event{
func newLog(logLevel LogLevel, format string, v ...any) Event {
return Event{
LogLevel: logLevel,
Payload: fmt.Sprintf(format, v...),
}
}
func PrintLog(logLevel LogLevel, format string, v ...interface{}) {
event := newLog(logLevel, format, v...)
logCh <- event
print(event)
}