oischinger / ha_vicare

Inofficial Home Assistant custom component for Viessmann ViCare API
61 stars 33 forks source link

Patch Logger to reduce repeated messages frequency #122

Closed krahabb closed 1 year ago

krahabb commented 1 year ago

Hello Hans, Sorry for this 'unsolicited' PR but I wanted to submit you a proposal for reducing the frequency of the integration logs which lead my working HA to some stressful situations (I have logging in ramdisk on my pi - so blame on me for that :) This happened sometimes when the Viessmann api was unavailable for many hours and my HA log got overwhelmed. I saw other complaints about this on HA forums too and I've decided to share with you my idea about the matter without opening an issue but directly here:

This patch basically sets a timeout (fixed in code but customizable 'per call') where a logged message doesnt get repeated until the timeout elapses. The idea is that once you know something wrong is happening there's no need to repeat this on every entity update cycle or so since the situation is likely stalling somewehere else and there's no actual solution (As stated before this happened a couple of time when the Viessmann api went offline for a long time)

The logic for 'gating' each message is handled in the patched Logger class (hidden behind _Logger in the added module helpers.py)

There's another issue in my opinion in the fact the entity update code is not totally tryed/catched so it happens sometimes some exceptions pop up in the runner and this starts an annoying stack dump also impairing the HA log readability. I'm thinking about a general catcher which just logs the error message in normal circumstances and eventually sets the stack trace only when logging is configured for DEBUG I'm working on a separate PR for this which I should be able to deliver in 1 or 2 days so to share the ideas

oischinger commented 1 year ago

Hey, thanks for the contribution. I believe however that this will get rejected from HA Core. They will ask to "properly" fix that by handling exceptions correctly etc. Basically what you already proposed via https://github.com/oischinger/ha_vicare/pull/123 I think we should work on this one instead of working around the improperly handled exceptions.

Other than that you can always get rid of some logs of a specific component via yaml:

# Example configuration.yaml entry
logger:
  default: info
  logs:
    homeassistant.components.vicare: critical