Code development platform for open source projects from the European Union institutions 🔵 EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content

Fix pretty print in logs

Pretty printing objects fails with the nms_logging module and prints newlines characters instead. This prevent an easy reading of the logs when debugging MRQ jobs for example. Here's how to reproduce this issue:

>>> from logging import DEBUG as DEBUG_LEVEL
>>> from nms_common import nms_logging
>>> logger = nms_logging.getAndConfigureLogger(name="LOGGER", level=DEBUG_LEVEL, owner_name="ntx", owner_type="team", app_name="changemanagement", app_type="app")
>>> from json import dumps
>>> logger.info(json.dumps(parsed, indent=4))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'json' is not defined
>>> import json
>>> parsed = {"a": {"b": 1}, "c": 2.012}
>>> logger.info(json.dumps(parsed, indent=4))
[2024-07-02T14:58:05.167][215575][LOGGER][INFO ][team:ntx][app:changemanagement]        {\n    "a": {\n        "b": 1\n    },\n    "c": 2.012\n}