TUN-3471: Add structured log context to logs

This commit is contained in:
Areg Harutyunyan
2020-12-28 18:10:01 +00:00
committed by Arég Harutyunyan
parent abab78730d
commit 55bf904689
40 changed files with 344 additions and 214 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/rs/zerolog"
)
const LogFieldLocation = "location"
type Observer struct {
log *zerolog.Logger
metrics *tunnelMetrics
@@ -28,7 +30,10 @@ func NewObserver(log *zerolog.Logger, tunnelEventChans []chan Event, uiEnabled b
func (o *Observer) logServerInfo(connIndex uint8, location, msg string) {
o.sendEvent(Event{Index: connIndex, EventType: Connected, Location: location})
o.log.Info().Msgf(msg)
o.log.Info().
Uint8(LogFieldConnIndex, connIndex).
Str(LogFieldLocation, location).
Msg(msg)
o.metrics.registerServerLocation(uint8ToString(connIndex), location)
}