49 lines
591 B
Go
49 lines
591 B
Go
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,
|
|
}
|
|
|
|
}
|