Closed Bento007 closed 7 years ago
So another possibility we could do is:
logger.error("%s", f"abcabcabc")
This standardizes us on the f-string formatting operations, which we are trending towards.
The downside is that we do the string formatting operation regardless of whether the logging is enabled.
check over f-strings in logs to avoid substituting a variable that includes a %. This may cause the logging expression to interpret the % as a variable substitution. This was observed when integrating the google could support for indexer.
from file dss/events/handlers/index.py line 42. Erroneous example:
logger.error(f"Exception occurred while processing GS event: {ex} Event: %s", json.dumps(event, indent=4))
after the f-string is evaluation this string is created:
The %2F in the url is evaluated as a variable substitution by logger which results in an exception being thrown because the incorrect number or type of parameters was provided. Here is how to avoid it.
Fixed Example:
logger.error("Exception occurred while processing GS event: %s Event: %s", ex, json.dumps(event, indent=4))
run test_indexer.TestGCPIndexer.test_debug_message_logged_when_indexing_an_invalid_bundle_name to see fix.