Need to change logging statements to fstrings
Closed this issue · 4 comments
Describe the bug
The current logging statements don't work properly if the application using the library has custom logging formats.
To Reproduce
Steps to reproduce the behavior:
Set up a custom logging format like this:
logging.basicConfig(level=logging.INFO, format='%(asctime)s.%(msecs)02d\t%(levelname)6s %(name)12s.%(funcName)-30s%(msg)s',datefmt='%Y-%m-%d %H:%M:%S')
self.logger = logging.getLogger("SimpliSafe")
When the library logs something with a % argument, you get:
2022-06-13 15:59:09.453 INFO simplipy._log_backoff Backing off %s(...) for %.1fs (%s)
When you fix it like this:
LOGGER.info(f"Websocket watchdog triggered – sleeping for {self._timeout_seconds} seconds")
You get:
2022-06-13 15:59:26.138 INFO simplipy.trigger Websocket watchdog triggered – sleeping for 300.0 seconds
You're comparing two different logs (one for a REST API backoff, one for the websocket watchdog)...
I just showed both situations, one where I already fixed it and one where I didn't. It happens everywhere.
Just use the message
attribute (instead of msg
):
%(asctime)s.%(msecs)02d\t%(levelname)6s %(name)12s.%(funcName)-30s%(message)s
msg
is just the raw message; message
includes the args passed to it.
Now there's a great API naming convention. I've been using that formatter for so long I forgot there was a difference.