Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bondhome] Suppress warning messages #15129

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Conversation

mlobstein
Copy link
Contributor

I am seeing occasional spurious warning messages from bondhome in my openhab.log like this:

image

This PR changes almost all warn() logging calls to trace() or debug() to prevent these messages from being logged.

Signed-off-by: Michael Lobstein <[email protected]>
@mlobstein mlobstein requested a review from ccutrer as a code owner June 21, 2023 21:49
@ccutrer
Copy link
Contributor

ccutrer commented Jun 21, 2023

I'd much rather understand what message you are getting that is not valid JSON.

@mlobstein
Copy link
Contributor Author

I'd much rather understand what message you are getting that is not valid JSON.

Hard to say. I could add the responseJson string to the logging call. I have not seen this often. Maybe it is just when the internet is down, the device is rebooting, etc..?

@ccutrer
Copy link
Contributor

ccutrer commented Jun 21, 2023

Well the BPUPListener is when the device sends us a message. And all communication is local - nothing goes over the internet.

So yes, if you could trace log the actual message received locally, then report the next time it happens, then we can decide what to do.

Do you need help compiling and installing a custom version of the addon with the extra logging?

@mlobstein
Copy link
Contributor Author

Well the BPUPListener is when the device sends us a message. And all communication is local - nothing goes over the internet.

So yes, if you could trace log the actual message received locally, then report the next time it happens, then we can decide what to do.

Do you need help compiling and installing a custom version of the addon with the extra logging?

Ok, I will add the extra logging and run it locally. I will report if the error is logged again with the json input.

@mlobstein
Copy link
Contributor Author

I'd much rather understand what message you are getting that is not valid JSON.

The issue has not reoccurred in a weeks time. I looked in my openhab & event logs and noticed that another device (using the shared jetty http client) went offline at the exact same moment. So I think it was a network hiccup that caused the json parse error. I still think this PR should be merged as it brings the use of logging calls closer to what is prescribed by the coding standards.

@lolodomo
Copy link
Contributor

@ccutrer : I let you first approve. As this PR is without any risk, we could still merge it in next coming days.

@ccutrer
Copy link
Contributor

ccutrer commented Jul 17, 2023

I'm not sure how this change more closely aligns with the logging standards at https://www.openhab.org/docs/administration/logging.html#defining-what-to-log. In normal operation none of these messages get logged. They're not debug level (because they're not logged under normal operation), and they are useful to a normal end user to pinpoint the problem interacting with their devices. With them a trace level, they may be having trouble controlling their devices or seeing the current device's status, and the log won't have any indication or problems whatsoever.

@mlobstein
Copy link
Contributor Author

I was referring to the coding guidelines for logging: https://www.openhab.org/docs/developer/guidelines.html#f-logging

warn logging should only be used

  • to inform the user that something seems to be wrong in the overall setup, but the system can nonetheless function as normal,
  • in recoverable situations when a section of code that is not accessed under normal operating conditions is reached.

Where there is an unexpected response from the device and the situation is not recoverable, then error would seems like the correct log to use along with setting the thing status appropriately. If there were a change to the device firmware that caused the code to stop working, some of the current warn logging calls such as when a null deviceId is encountered, would flood the log with the same message over and over again. I think this is why the guidelines call for minimal use of warn and error logging.

@jlaur
Copy link
Contributor

jlaur commented Jul 20, 2023

I'd much rather understand what message you are getting that is not valid JSON.

Hard to say. I could add the responseJson string to the logging call.

It's already logged in line 232 if you enable debug level:

public @Nullable BPUPUpdate transformUpdatePacket(final DatagramPacket packet) {
String responseJson = new String(packet.getData(), 0, packet.getLength(), UTF_8);
logger.debug("Message from {}:{} -> {}", packet.getAddress().getHostAddress(), packet.getPort(), responseJson);
@Nullable
BPUPUpdate response = null;
try {
response = this.gsonBuilder.fromJson(responseJson, BPUPUpdate.class);
} catch (JsonParseException e) {
logger.warn("Error parsing json! {}", e.getMessage());
}
return response;
}

@jlaur
Copy link
Contributor

jlaur commented Nov 13, 2023

@ccutrer, @mlobstein - should we try to reach a conclusion? 🙂 We can probably agree that IllegalStateException warnings are not expected, the question is how to best avoid that?

@mlobstein
Copy link
Contributor Author

mlobstein commented Nov 14, 2023

@ccutrer, @mlobstein - should we try to reach a conclusion? 🙂 We can probably agree that IllegalStateException warnings are not expected, the question is how to best avoid that?

If there is some sort of persistent problem reported by a user in the forums, the advice is given almost universally to turn on debug or trace logging. Thus it made sense to me to prevent the logging of spurious errors at the warn level. The messages to be changed are more aligned to the definition and usage of debug level messages in the coding guidelines:

https://www.openhab.org/docs/developer/guidelines.html#f-logging

  • debug logging should be used for detailed logging
    • to give the user debug information in cases of unexpected behavior.
    • to log exceptions in case of temporary problems, like connection problems. In case of such exceptions this should be reflected in an updated state of the binding.

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@jlaur jlaur merged commit ab0ea34 into openhab:main Nov 14, 2023
@jlaur jlaur added this to the 4.1 milestone Nov 14, 2023
@mlobstein mlobstein deleted the bondhome_warn branch November 14, 2023 14:50
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Nov 26, 2023
austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
Signed-off-by: Michael Lobstein <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants