Hey all! I've setup `PREFECT__LOGGING__FORMAT` to ...
# ask-community
w
Hey all! I've setup
PREFECT__LOGGING__FORMAT
to be a JSON-style string, and I've set
PREFECT__LOGGING__EXTRA_LOGGERS
to capture logging from various libraries as well. The issue is the
%(message)s
strings that get sent to loggers often come back from libraries and things in a format that is not JSON-compatible. For example, they will have double-quotes in them that are not escaped, and I want to catch these so I can pass everything to
json.JSONEncoder().encode(msg)
first. Is there a way to do this? Even if I need to write a different "main" method that sets up an agent for me, I'm willing to do that. I just need to know how/where to setup the hooks. Much appreciated for any information in advance!!
a
@William Grim I’m not sure how you can accomplish that. But this LogManager can be something you can probably subclass and adjust: https://github.com/PrefectHQ/prefect/blob/master/src/prefect/utilities/logging.py
w
Thanks @Anna Geller. I see that file actually calls some of the functions when it's imported. I'm guessing if I wrap the cli but configure the logger right before doing that, it might work. I'll try that tomorrow. Thank you!!
upvote 1