-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
40 lines (29 loc) · 686 Bytes
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package logger
import (
"io"
"os"
"github.com/rs/zerolog"
)
type Logger struct {
writer io.Writer
}
type LoggerConfig struct {
ConsoleWriter bool
FileWriter
}
func New(loggerConfig *LoggerConfig) *Logger {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
var writers []io.Writer
if loggerConfig.ConsoleWriter {
writers = append(writers, zerolog.ConsoleWriter{Out: os.Stderr})
}
if loggerConfig.FileWriter != nil {
writers = append(writers, loggerConfig.FileWriter)
}
multiWriter := io.MultiWriter(writers...)
return &Logger{multiWriter}
}
func (l *Logger) Sub(topic string) *SubLogger {
logger := zerolog.New(l.writer)
return &SubLogger{topic, &logger}
}