Files
logger/resource.go
2025-05-09 18:32:06 +02:00

46 lines
615 B
Go

// logger is a async logger
package logger
import (
"fmt"
"git.schreifuchs.ch/schreifuchs/logger/lvl"
)
type Log struct {
Message string
Level lvl.Level
}
type Logger struct {
Level lvl.Level
LogChan chan *Log
// OutFile io.Writer
}
func New(l lvl.Level) *Logger {
c := make(chan *Log, 20)
go func() {
for log := range c {
fmt.Printf("%v: %s\n", log.Level, log.Message)
}
}()
return &Logger{
Level: l,
LogChan: c,
}
}
func NewWithStrategy(lvl lvl.Level, log func(<-chan *Log)) *Logger {
c := make(chan *Log, 20)
go log(c)
return &Logger{
Level: lvl,
LogChan: c,
}
}