Closed vikramsubramanian closed 2 months ago
Hi
The "text"
attribute represents the log formatted according to the format
argument, while the "message"
attribute is the raw message as passed to the logging function.
Maybe you can clear the "text"
attribute by specifying an empty format like so:
logger.add(sink=sys.stdout, level=level, format="", serialize=True)
Empty string in format almost solve this problem, there a still newline in text field but I think this solves double log message size problem and this should be enough.
>>> logger.add(sink=sys.stdout, level=level, format="", serialize=True)
foo | 1
>>> logger.info("test message")
foo | {"text": "\n", "record": {"elapsed": {"repr": "0:00:28.989323", "seconds": 28.989323}, "exception": null, "extra": {}, "file": {"name": "<input>", "path": "<input>"}, "function": "<module>", "level": {"icon": "??", "name": "INFO", "no": 20}, "line": 1, "message": "test message", "module": "<input>", "name": "camunda_responder.settings", "process": {"id": 1, "name": "MainProcess"}, "thread": {"id": 140499480377152, "name": "MainThread"}, "time": {"repr": "2022-02-17 09:58:12.398011+03:00", "timestamp": 1645081092.398011}}}
Thanks 👍
You're welcome. :+1:
You can also use a formatter function to get ride of the `"\n" (which is automatically added for convenience):
logger.add(sink=sys.stdout, level=level, format=lambda _: "", serialize=True)
Alternatively, you can implement your own serializing sink:
def sink(record):
print(json.dumps(message.record, default=str))
logger.add(sink)
Hi. Thanks for great lib! But I have a question. We use loguru for simple logging in JSON format. And when I enable serialization, text in log records is duplicated in text field and in record.message.
Is there a way to disable this duplication?
And I think because of that logs take twice much space and double the size of each log message. For me this default is not obvious. Thanks.