-
Notifications
You must be signed in to change notification settings - Fork 712
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
Logging the exception calls again the function in which it happened #155
Comments
Here is a draft for a test: def test_exception_in_property(writer):
logger.add(writer, format="{message}")
class A:
@property
def value(self):
try:
1 / 0
except:
logger.opt(exception=True).debug("test")
return None
else:
return "never"
a = A()
value = a.value
lines = writer.read().strip().splitlines()
assert lines[0] == "test"
assert lines[-1] == "ZeroDivisionError: division by zero" But I'm not sure it makes sense because if it does not work, it will break the test runner. |
Issue was coming from |
Well, I'm glad it has been fixed in more recent release, but I don't really know why... 😄 There was indeed a refactoring of everything related to the exceptions formated. It seems related to the backtracing process fetching previous stack frames. So, I gonna take the |
No problem! I didn't try the test code though |
I tested it and it failed just as expected, while it worked fine with the latest Loguru version. I will update it adequately if needed, thanks again. 👍 |
Might be related to #88.
I noticed this issue because my tests (ran with
pytest
) were breaking when I added a fixture to enable the logger.Here is some minimal example. I added comments to explain what seems to happen.
In the generated log file, I then have 91 lines with the same warning. I tried adding
depth=-1
in theopt()
parameters, but it changes nothing. The instance ofSomeException
does not contain any reference to theWhatever
instance..opt(exception=True)
it works fine again (but I get no traceback)logger.opt(exception=error).trace(error)
it works as well, but it does not print the traceback.logger.opt(exception=sys.exc_info()).trace(error)
, it does not work.exc_info = sys.exc_info()
, without logging it, it works fine (so the issue must come from what loguru does with the exception).I guess the
following
property is triggered when inspectingsys.exc_info
or something? Is there anything loguru can do about this? If not, I can still pass the exception directly so it's not so bad. It would be interesting to replicate this in a test though.The text was updated successfully, but these errors were encountered: