mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-16 13:17:19 +02:00
all: eliminate usage of global ProxyLogger
So setting up logging for ctrld binary and ctrld packages could be done more easily, decouple the required setup for interactive vs daemon running. This is the first step toward replacing rs/zerolog libary with a different logging library.
This commit is contained in:
committed by
Cuong Manh Le
parent
47c04bf0f6
commit
0e66697247
+10
-10
@@ -13,9 +13,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"tailscale.com/net/netmon"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"tailscale.com/net/netmon"
|
||||
"tailscale.com/util/lineread"
|
||||
|
||||
"github.com/Control-D-Inc/ctrld"
|
||||
@@ -30,6 +29,7 @@ type dhcp struct {
|
||||
|
||||
watcher *fsnotify.Watcher
|
||||
selfIP string
|
||||
logger *ctrld.Logger
|
||||
}
|
||||
|
||||
func (d *dhcp) init() error {
|
||||
@@ -52,7 +52,7 @@ func (d *dhcp) watchChanges() {
|
||||
}
|
||||
if dir := router.LeaseFilesDir(); dir != "" {
|
||||
if err := d.watcher.Add(dir); err != nil {
|
||||
ctrld.ProxyLogger.Load().Err(err).Str("dir", dir).Msg("could not watch lease dir")
|
||||
d.logger.Err(err).Str("dir", dir).Msg("could not watch lease dir")
|
||||
}
|
||||
}
|
||||
for {
|
||||
@@ -64,7 +64,7 @@ func (d *dhcp) watchChanges() {
|
||||
if event.Has(fsnotify.Create) {
|
||||
if format, ok := clientInfoFiles[event.Name]; ok {
|
||||
if err := d.addLeaseFile(event.Name, format); err != nil {
|
||||
ctrld.ProxyLogger.Load().Err(err).Str("file", event.Name).Msg("could not add lease file")
|
||||
d.logger.Err(err).Str("file", event.Name).Msg("could not add lease file")
|
||||
}
|
||||
}
|
||||
continue
|
||||
@@ -72,14 +72,14 @@ func (d *dhcp) watchChanges() {
|
||||
if event.Has(fsnotify.Write) || event.Has(fsnotify.Rename) || event.Has(fsnotify.Chmod) || event.Has(fsnotify.Remove) {
|
||||
format := clientInfoFiles[event.Name]
|
||||
if err := d.readLeaseFile(event.Name, format); err != nil && !os.IsNotExist(err) {
|
||||
ctrld.ProxyLogger.Load().Err(err).Str("file", event.Name).Msg("leases file changed but failed to update client info")
|
||||
d.logger.Err(err).Str("file", event.Name).Msg("leases file changed but failed to update client info")
|
||||
}
|
||||
}
|
||||
case err, ok := <-d.watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
ctrld.ProxyLogger.Load().Err(err).Msg("could not watch client info file")
|
||||
d.logger.Err(err).Msg("could not watch client info file")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (d *dhcp) dnsmasqReadClientInfoReader(reader io.Reader) error {
|
||||
}
|
||||
ip := normalizeIP(string(fields[2]))
|
||||
if net.ParseIP(ip) == nil {
|
||||
ctrld.ProxyLogger.Load().Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
d.logger.Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
ip = ""
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ func (d *dhcp) iscDHCPReadClientInfoReader(reader io.Reader) error {
|
||||
case "lease":
|
||||
ip = normalizeIP(strings.ToLower(fields[1]))
|
||||
if net.ParseIP(ip) == nil {
|
||||
ctrld.ProxyLogger.Load().Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
d.logger.Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
ip = ""
|
||||
}
|
||||
case "hardware":
|
||||
@@ -328,7 +328,7 @@ func (d *dhcp) keaDhcp4ReadClientInfoReader(r io.Reader) error {
|
||||
}
|
||||
ip := normalizeIP(record[0])
|
||||
if net.ParseIP(ip) == nil {
|
||||
ctrld.ProxyLogger.Load().Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
d.logger.Warn().Msgf("invalid ip address entry: %q", ip)
|
||||
ip = ""
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ func (d *dhcp) keaDhcp4ReadClientInfoReader(r io.Reader) error {
|
||||
func (d *dhcp) addSelf() {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
ctrld.ProxyLogger.Load().Err(err).Msg("could not get hostname")
|
||||
d.logger.Err(err).Msg("could not get hostname")
|
||||
return
|
||||
}
|
||||
hostname = normalizeHostname(hostname)
|
||||
|
||||
Reference in New Issue
Block a user