Skip to content

Commit

Permalink
fix(plc4go/cbus): rework the way conditional logging is made
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 9, 2023
1 parent 9d62036 commit 2c7e786
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions plc4go/internal/cbus/Browser.go
Expand Up @@ -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")
Expand All @@ -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")
}
Expand All @@ -132,17 +132,17 @@ 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")
continue 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).
Expand Down
30 changes: 15 additions & 15 deletions plc4go/protocols/cbus/readwrite/model/StaticHelper.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2c7e786

Please sign in to comment.