forked from 9seconds/topographer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
35 lines (27 loc) · 875 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
package main
import (
"net"
"os"
"github.com/9seconds/topographer/topolib"
"github.com/rs/zerolog"
)
type logger struct {
lookupLog zerolog.Logger
updateLog zerolog.Logger
}
func (l *logger) LookupError(ip net.IP, name string, err error) {
l.lookupLog.Error().Str("provider", name).Stringer("ip", ip).Err(err).Msg("")
}
func (l *logger) UpdateInfo(name string) {
l.updateLog.Info().Str("provider", name).Msg("Database was updated")
}
func (l *logger) UpdateError(name string, err error) {
l.updateLog.Error().Str("provider", name).Err(err).Msg("")
}
func newLogger() topolib.Logger {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
return &logger{
lookupLog: zerolog.New(os.Stderr).With().Timestamp().Stack().Str("event_name", "lookup").Logger(),
updateLog: zerolog.New(os.Stderr).With().Timestamp().Stack().Str("event_name", "update").Logger(),
}
}