Python Forum
logger option , where is the file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logger option , where is the file?
#1
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,
Reply
#2
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 853 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  how to write exception error into logger mg24 3 948 Nov-15-2022, 04:20 PM
Last Post: insharazzak
  python insert blank line in logger mg24 1 2,729 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 1,350 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger from other function problem Paqqno 1 1,084 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  Closing logger to rename directory malcoverc 1 1,175 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  How to assign input file name as logger name Mekala 5 2,790 Aug-05-2020, 12:54 AM
Last Post: Larz60+
  Need help implmenting if/else or case statements for option to choose file format. samlee916 1 1,973 Jul-22-2020, 06:06 PM
Last Post: Larz60+
  file with option afang_ndong 2 2,048 May-14-2020, 07:31 AM
Last Post: snippsat
  Logger file rotation not working when python code started from windows service as exe nirvantosh 1 6,562 Jun-14-2019, 03:58 PM
Last Post: nirvantosh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020