|
fields[key] = repr(value) |
The value of extra fields are formatted via repr(). In most cases it seems to me that str() would be better. A typical example is Path objects:
from pathlib import Path
path = Path("foo/bar")
print(repr(path))
print(str(path))
The repr-version is PosixPath('foo/bar'), whereas the str-version is foo/bar. In logs, I always want to have the latter version and, currently, have to manually enforce this via extra={"path": str(path)}. This is also true for many other objects.
According to Python docs repr() should return "the “official” string representation of an object" whereas str() should return a "nicely printable string representation of an object". For logs, I think, the latter is almost always what one wants.
Therefore my question: would you be open to changing the formatting of extra fields from repr() to str()? Am I missing some reason why it is a bad idea? If you agree, I would submit a PR.
python-logstash/logstash/formatter.py
Line 45 in a8be251
The value of extra fields are formatted via
repr(). In most cases it seems to me thatstr()would be better. A typical example isPathobjects:The repr-version is
PosixPath('foo/bar'), whereas the str-version isfoo/bar. In logs, I always want to have the latter version and, currently, have to manually enforce this viaextra={"path": str(path)}. This is also true for many other objects.According to Python docs
repr()should return "the “official” string representation of an object" whereasstr()should return a "nicely printable string representation of an object". For logs, I think, the latter is almost always what one wants.Therefore my question: would you be open to changing the formatting of extra fields from
repr()tostr()? Am I missing some reason why it is a bad idea? If you agree, I would submit a PR.