Python Forum
logger option , where is the file? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: logger option , where is the file? (/thread-33436.html)



logger option , where is the file? - korenron - Apr-25-2021

Hello ,
I notice in many examples there is a logger
import loggin 
 logger = logging.getLogger('localGATT')
 logger.setLevel(logging.DEBUG)
but I don't see any referance to the file
where can I find it ?
or is it something I need to setup also ? - of so what to do ?
will this do?
logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s')
and then in the file I will get all the debug data ?

Thanks,


RE: logger option , where is the file? - snippsat - Apr-25-2021

Look at this post for basic setup.
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'