diff --git a/Changelog.md b/Changelog.md index 074fafc..8108a91 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ ## [UNRELEASED] +- Reduce log metadata and volume + ## [2.7.0] - 2025-10-15 ### Added diff --git a/src/dividat-driver/senso/main.go b/src/dividat-driver/senso/main.go index 2b0ce4f..4a36d10 100644 --- a/src/dividat-driver/senso/main.go +++ b/src/dividat-driver/senso/main.go @@ -72,9 +72,9 @@ func (handle *Handle) Connect(address string) { handle.broker.TryPub(data, "rx") } - go connectTCP(ctx, handle.log.WithField("channel", "data"), address+":55568", handle.broker.Sub("noTx"), onReceive) + go connectTCP(ctx, handle.log.WithField("channel", "data"), address+":55568", handle.broker.Sub("noTx"), onReceive, true) time.Sleep(1000 * time.Millisecond) - go connectTCP(ctx, handle.log.WithField("channel", "control"), address+":55567", handle.broker.Sub("tx"), onReceive) + go connectTCP(ctx, handle.log.WithField("channel", "control"), address+":55567", handle.broker.Sub("tx"), onReceive, false) handle.cancelCurrentConnection = cancel } diff --git a/src/dividat-driver/senso/tcp.go b/src/dividat-driver/senso/tcp.go index 6794063..31c2d77 100644 --- a/src/dividat-driver/senso/tcp.go +++ b/src/dividat-driver/senso/tcp.go @@ -20,11 +20,19 @@ const maxInterval = 30 * time.Second type onReceive = func([]byte) // connectTCP creates a persistent tcp connection to address -func connectTCP(ctx context.Context, baseLogger *logrus.Entry, address string, tx chan interface{}, onReceive onReceive) { +// isOptional is used when connecting to the data channel, which is used only in legacy Senso firmware +func connectTCP(ctx context.Context, baseLogger *logrus.Entry, address string, tx chan interface{}, onReceive onReceive, isOptional bool) { var dialer net.Dialer var log = baseLogger.WithField("address", address) + var connectionAttemptLogLevel logrus.Level + if isOptional { + connectionAttemptLogLevel = logrus.DebugLevel + } else { + connectionAttemptLogLevel = logrus.InfoLevel + } + var conn net.Conn dialTCP := func() error { @@ -34,11 +42,11 @@ func connectTCP(ctx context.Context, baseLogger *logrus.Entry, address string, t conn.Close() } - log.Info("Dialing TCP connection.") + log.Log(connectionAttemptLogLevel, "Dialing TCP connection.") conn, connErr = dialer.DialContext(ctx, "tcp", address) if connErr != nil { - log.WithError(connErr).Info("Could not connect with Senso.") + log.WithError(connErr).Log(connectionAttemptLogLevel, "Could not connect with Senso.") } return connErr } diff --git a/src/dividat-driver/server/main.go b/src/dividat-driver/server/main.go index 94f5bfe..c4b061e 100644 --- a/src/dividat-driver/server/main.go +++ b/src/dividat-driver/server/main.go @@ -37,12 +37,6 @@ func Start(logger *logrus.Logger, origins []string) context.CancelFunc { baseLog.WithError(err).Panic("Could not get system information.") } - baseLog = baseLog.WithFields(logrus.Fields{ - "machineId": systemInfo.MachineId, - "os": systemInfo.Os, - "arch": systemInfo.Arch, - }) - baseLog.Info("Dividat Driver starting") // Setup log endpoint @@ -68,9 +62,6 @@ func Start(logger *logrus.Logger, origins []string) context.CancelFunc { // Create a logger for server log := baseLog.WithField("package", "server") - // Start the monitor - go startMonitor(baseLog.WithField("package", "monitor")) - // Setup HTTP Server server := http.Server{Addr: "127.0.0.1:" + serverPort} diff --git a/src/dividat-driver/server/monitor.go b/src/dividat-driver/server/monitor.go deleted file mode 100644 index 95f9121..0000000 --- a/src/dividat-driver/server/monitor.go +++ /dev/null @@ -1,19 +0,0 @@ -package server - -import ( - "runtime" - "time" - - "github.com/sirupsen/logrus" -) - -func startMonitor(log *logrus.Entry) { - var m runtime.MemStats - - c := time.NewTicker(30 * time.Second).C - - for range c { - runtime.ReadMemStats(&m) - log.WithField("heapAlloc", m.HeapAlloc).WithField("routines", runtime.NumGoroutine()).Info("Monitoring runtime.") - } -}