Closed vikramsubramanian closed 2 weeks ago
hashtaghashtaghashtaghashtag Additional Info
Also the log file out.log
created by above code has:
2022-05-23 00:11:02.830 | ERROR | __main__:<module>:1 - An error has been caught in function '<module>', process 'MainProcess' (12040), thread 'MainThread' (2052):
Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in my_function
ZeroDivisionError: division by zero
Hi. Thanks for detailed report.
Stack trace context isn't available when Python is executed in an interactive shell. This is a Python technical limitation and unfortunately, there is nothing I can do to fix it.
Hi
Thanks for the reply. Alright, the GIF at the very beginning of the readme suggests it should work.
Anyway, I did the following to check if what you said is true.
main.py
from loguru import logger
def my_function(x, y, z):
hashtag An error? It's caught anyway!
return 1 / (x + y + z)
def main():
logger.add("out.log", backtrace=True, diagnose=True)
my_function(0, 0, 0)
if __name__ == '__main__':
main()
conda activate loguru
python main.py
I then indeed get:
2022-05-23 12:05:39.791 | ERROR | __main__:main:10 - An error has been caught in function 'main', process 'MainProcess' (23152), thread 'MainThread' (20928):
Traceback (most recent call last):
File "main.py", line 13, in <module>
main()
└ <function main at 0x0000029259088EE0>
> File "main.py", line 10, in main
my_function(0, 0, 0)
└ <function my_function at 0x0000029256F024C0>
File "main.py", line 6, in my_function
return 1 / (x + y + z)
│ │ └ 0
│ └ 0
└ 0
ZeroDivisionError: division by zero
Which is exactly what I expected.
![image](
I do not know if many people fall for this, but I suggest to note this behaviour in the readme as a hint or something. It could avoid confusion about this.
Thanks for the quick response!
Well, you're not alone:
The .gif
is indeed misleading, sorry for that. It would be better to change it or add a note underneath, but I can't do that without compromising the desired look of the Readme. I added a note under the "Fully descriptive exceptions" section. Hopefully it will reduce confusion a little.
hashtaghashtaghashtaghashtag Environment I use Anaconda and python inside a conda environment. Python version:
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
OS:Windows 11
Loguru version:0.6.0
hashtaghashtaghashtaghashtag Issue description When using the ` decorator on a function I do not get the expected output with the entire stack trace and the values of variables.
hashtaghashtaghashtaghashtag Steps to reproduce the issue
loguru
withhashtaghashtaghashtaghashtag What's the expected result?
hashtaghashtaghashtaghashtag What's the actual result?
hashtaghashtaghashtaghashtag Additional details / screenshot
![image](