You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
above code throws a exception which tell us that name has already been existed in LogRecord
output
Traceback (most recent call last):
File "json_logger.py", line 14, in <module>
logger.info("test", extra={"name": "my_test_name"})
File "/data/zhouzhao.zyl/repos/meta_service/venv/lib/python3.7/logging/__init__.py", line 1383, in info
self._log(INFO, msg, args, **kwargs)
File "/data/zhouzhao.zyl/repos/meta_service/venv/lib/python3.7/logging/__init__.py", line 1518, in _log
exc_info, func, extra, sinfo)
File "/data/zhouzhao.zyl/repos/meta_service/venv/lib/python3.7/logging/__init__.py", line 1492, in makeRecord
raise KeyError("Attempt to overwrite %r in LogRecord" % key)
KeyError: "Attempt to overwrite 'name' in LogRecord"
Reading the related source code of logging, the name key has been set as myname as the logger name.
so I am seriously curious about that if the way of using extra in my code is correct?
python json logger version
python-json-logger 2.0.7
l
The text was updated successfully, but these errors were encountered:
emmm, I think it's inconvenient for users to use json formatter when there are so many reserve fields. As a formatter, it should format everything that user inputs.
Per the stack trace you provided, this error is being generated by logging and not python-json-logger.
Despite the package name, python-json-logger is actually a logging.Formatter and is only called from a logging.Handler (which in turn must be attached to a logging.Logger).
The reserved names are enforced by the default logging.Logger.makeRecord implementation. If you'd like to be able to override any name using extra= you'll need to create your own logging.Logger subclass and override this method.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
above code throws a exception which tell us that name has already been existed in LogRecord
output
Reading the related source code of logging, the name key has been set as myname as the logger name.
so I am seriously curious about that if the way of using extra in my code is correct?
python json logger version
python-json-logger 2.0.7
l
The text was updated successfully, but these errors were encountered: