KeyError: "Attempt to overwrite 'args' in LogRecord"
See original GitHub issueExpected result:
I am able to use args
as keyword to denote argument to string interpolation when using loguru
Actual result:
Opposite of above 😉.In fact it seems that if you try to specify whatever is originally available in Record from logging
of python, python will think you are crazy to put such things in record.
Facts
loguur.__version__ = 0.5.0
python --version = Python 3.7.6
lsb_release -sd = Linux Mint 19.3 Tricia
context = application
Reproduce
git clone https://github.com/kornicameister/axion.git /tmp/axion --depth 1 ; \
cd /tmp/axion ; \
git checkout c9d85e76bd48719aab7edded1d4287a52ecb145e \
command -v tox && tox -e "py37-test" -- -k test_not_empty_signature || echo "need tox" ; \
cd - \
rm -rf /tmp/axion
Root cause
Relevant line that causes issue available here
Alternatively, it might be caused by conftest#caplog
here, but this is unlikely given that only one test fails 😉
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
python - Why is it forbidden to override log record attributes?
Looking at the _ _ init _ _() method in that file, we can see that it sets a long list of attributes,...
Read more >logging.error('asdf', extra={'msg':123}) raise KeyError exception
KeyError : "Attempt to overwrite 'msg' in LogRecord" Originally code was extra=locals() and 'msg' was local variable, but it doesn't matter.
Read more >logging — Pyrocko v2020.10.26 Manual
The main information passed in is in msg and args, which are combined using ... __dict__): raise KeyError("Attempt to overwrite %r in LogRecord"...
Read more >Python Examples of logging.LogRecord - ProgramCreek.com
Args : record: logging.LogRecord, the record to get ... __dict__): raise KeyError("Attempt to overwrite %r in LogRecord" % key) rv.__dict__[key] = extra[key] ...
Read more >API Reference - structlog 22.3.0 documentation
LogRecord objects to the event dictionary. This processor can be used for adding data passed in the extra parameter of the logging module's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, I modified the way the
LogRecord
is filled withextra
.The main downside is that it’s no longer possible to use
Formatter("[%(some_extra_field)s] %(message)s")
with standardlogging
handler, but I think it’s certainly less of a problem than the"Attempt to overwrite"
error was.Closing thie issue consequently. Discussion about
mypy
plugins moved here: #277There exists type hints for
loguru
, anyone should be able to benefit from it usingmypy
, right?I opened https://github.com/kornicameister/axion/issues/328 to discuss usage of
loguru
in your project. 😃