Look at this post for basic setup.
I would advice to use Loguru
Then all boilerplate code that no one can remember is gone.
I would advice to use Loguru
Then all boilerplate code that no one can remember is gone.
from loguru import logger logger.add("error.log", backtrace=True, diagnose=True) def add(x, y): try: return(x + y) except Exception as error: logger.exception('msg') if __name__ == '__main__': print(add(5, '50')) # Make error
error.log
Output:2021-04-25 15:25:25.155 | ERROR | __main__:add:8 - msg
Traceback (most recent call last):
File "<string>", line 178, in run_nodebug
File "E:\div_code\new\log_guru.py", line 11, in <module>
add(5, '50')
-> <function add at 0x00000000632BDAF0>
> File "E:\div_code\new\log_guru.py", line 6, in add
return(x + y)
| -> '50'
-> 5
TypeError: unsupported operand type(s) for +: 'int' and 'str'