From 2c7e786c8e11d3c5e44d81fc2b41965274b60e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Wed, 9 Aug 2023 09:21:52 +0200 Subject: [PATCH] fix(plc4go/cbus): rework the way conditional logging is made --- plc4go/internal/cbus/Browser.go | 14 ++++----- .../cbus/readwrite/model/StaticHelper.go | 30 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plc4go/internal/cbus/Browser.go b/plc4go/internal/cbus/Browser.go index 7c03690e12a..ee6e3f79f2c 100644 --- a/plc4go/internal/cbus/Browser.go +++ b/plc4go/internal/cbus/Browser.go @@ -96,11 +96,11 @@ unitLoop: Uint8("unitAddress", unitAddress). Msg("Querying all attributes of unit") } - event := m.log.Info() + level := zerolog.InfoLevel if allUnits { - event = m.log.Debug() + level = zerolog.DebugLevel } - event.Uint8("unitAddress", unitAddress).Msg("Query unit") + m.log.WithLevel(level).Uint8("unitAddress", unitAddress).Msg("Query unit") for _, attribute := range attributes { if err := ctx.Err(); err != nil { unitLog.Info().Err(err).Msg("Aborting scan at unit") @@ -112,7 +112,7 @@ unitLoop: Stringer("attribute", attribute). Msg("Querying attribute of unit") } else { - event.Uint8("unitAddress", unitAddress). + m.log.WithLevel(level).Uint8("unitAddress", unitAddress). Stringer("attribute", attribute). Msg("unit unitAddress: Query attribute") } @@ -132,9 +132,9 @@ unitLoop: timeoutCancel() if err := requestResult.GetErr(); err != nil { if allUnits || allAttributes { - event = m.log.Trace() + level = zerolog.TraceLevel } - event.Err(err). + m.log.WithLevel(level).Err(err). Uint8("unitAddress", unitAddress). Stringer("attribute", attribute). Msg("unit unitAddress: Can't read attribute attribute") @@ -142,7 +142,7 @@ unitLoop: } response := requestResult.GetResponse() if code := response.GetResponseCode(readTagName); code != apiModel.PlcResponseCode_OK { - event. + m.log.WithLevel(level). Uint8("unitAddress", unitAddress). Stringer("attribute", attribute). Stringer("code", code). diff --git a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go index 5e5d0b191f8..8c7400e7c64 100644 --- a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go +++ b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go @@ -144,7 +144,7 @@ func readBytesFromHex(ctx context.Context, logicalName string, readBuffer utils. readBuffer.Reset(readBuffer.GetPos() - 2) rawBytes = rawBytes[:len(rawBytes)-1] } - log.Trace().Int("n", n).Msg("%d bytes decoded") + log.Trace().Int("n", n).Msg("n bytes decoded") return rawBytes, nil } @@ -195,7 +195,7 @@ func encodeHexUpperCase(dst, src []byte) int { return len(src) * 2 } -func KnowsCALCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsCALCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -205,7 +205,7 @@ func KnowsCALCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuff return CALCommandTypeContainerKnows(readUint8) } -func KnowsLightingCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsLightingCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -215,7 +215,7 @@ func KnowsLightingCommandTypeContainer(ctx context.Context, readBuffer utils.Rea return LightingCommandTypeContainerKnows(readUint8) } -func KnowsSecurityCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsSecurityCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -225,7 +225,7 @@ func KnowsSecurityCommandTypeContainer(ctx context.Context, readBuffer utils.Rea return SecurityCommandTypeContainerKnows(readUint8) } -func KnowsMeteringCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsMeteringCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -235,7 +235,7 @@ func KnowsMeteringCommandTypeContainer(ctx context.Context, readBuffer utils.Rea return MeteringCommandTypeContainerKnows(readUint8) } -func KnowsTriggerControlCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsTriggerControlCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -245,7 +245,7 @@ func KnowsTriggerControlCommandTypeContainer(ctx context.Context, readBuffer uti return TriggerControlCommandTypeContainerKnows(readUint8) } -func KnowsEnableControlCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsEnableControlCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -255,7 +255,7 @@ func KnowsEnableControlCommandTypeContainer(ctx context.Context, readBuffer util return EnableControlCommandTypeContainerKnows(readUint8) } -func KnowsTemperatureBroadcastCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsTemperatureBroadcastCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -265,7 +265,7 @@ func KnowsTemperatureBroadcastCommandTypeContainer(ctx context.Context, readBuff return TemperatureBroadcastCommandTypeContainerKnows(readUint8) } -func KnowsAccessControlCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsAccessControlCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -275,7 +275,7 @@ func KnowsAccessControlCommandTypeContainer(ctx context.Context, readBuffer util return AccessControlCommandTypeContainerKnows(readUint8) } -func KnowsMediaTransportControlCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsMediaTransportControlCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -285,7 +285,7 @@ func KnowsMediaTransportControlCommandTypeContainer(ctx context.Context, readBuf return MediaTransportControlCommandTypeContainerKnows(readUint8) } -func KnowsClockAndTimekeepingCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsClockAndTimekeepingCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -295,7 +295,7 @@ func KnowsClockAndTimekeepingCommandTypeContainer(ctx context.Context, readBuffe return ClockAndTimekeepingCommandTypeContainerKnows(readUint8) } -func KnowsTelephonyCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsTelephonyCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -305,7 +305,7 @@ func KnowsTelephonyCommandTypeContainer(ctx context.Context, readBuffer utils.Re return TelephonyCommandTypeContainerKnows(readUint8) } -func KnowsAirConditioningCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsAirConditioningCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -315,7 +315,7 @@ func KnowsAirConditioningCommandTypeContainer(ctx context.Context, readBuffer ut return AirConditioningCommandTypeContainerKnows(readUint8) } -func KnowsMeasurementCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsMeasurementCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8) @@ -325,7 +325,7 @@ func KnowsMeasurementCommandTypeContainer(ctx context.Context, readBuffer utils. return MeasurementCommandTypeContainerKnows(readUint8) } -func KnowsErrorReportingCommandTypeContainer(ctx context.Context, readBuffer utils.ReadBuffer) bool { +func KnowsErrorReportingCommandTypeContainer(_ context.Context, readBuffer utils.ReadBuffer) bool { oldPos := readBuffer.GetPos() defer readBuffer.Reset(oldPos) readUint8, err := readBuffer.ReadUint8("", 8)