-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom serializers #372
Comments
I'm leaving this idea here, but will come back tomorrow with a pull request for this proposal 😃 |
I was thinking on using a custom sink with serialize=True, that would serve the same purpose except I would have to de-serialize each time and the overhead would be terrific 😞 |
Hi! Thanks for your interest on This feature has been requested several times but so far I have always been reluctant to add it. I don't know if you saw it but there exists a snippet in the documentation: Serializing log messages using a custom function I think using a custom def formatter(record):
record["extra"]["serialized"] = orjson.dumps(record, default=str)
return "{extra[serialized]}\n"
logger.add("file.log", format=formatter) In this way, the user has the possibility to customize the serialization process entirely. |
The patch() function is actually better for what I was looking for! Thanks and thanks for this great library! |
Thanks for your understanding, @XayOn! |
The hability to specify a custom serializer for a file could be useful to save files in human-readable serializable formats such as the one followed by splunk. This would also open a door to save pickled, xml or any other log format the user wants (for whatever reason... I cant think of a good one to save pickled data or xml in logs tbh).
Should be simple enough. I'm proposing a backwards-compatible implementation where serializer is either a boolean, or a custom serializer directly.
loguru/loguru/_handler.py
Line 258 in 1b41299
The text was updated successfully, but these errors were encountered: