How to create a log...
 
Share:
Notifications
Clear all

How to create a log file in Python script?


myTechMint
(@mytechmint)
Member Moderator
Joined: 1 year ago
Posts: 52
Topic starter  

How to create a log file in Python script?


Quote
Topic Tags
myTechMint
(@mytechmint)
Member Moderator
Joined: 1 year ago
Posts: 52
Topic starter  

You can use the logging module to accomplish this.

import logging

At the very easiest level, it will be set up like this:

logging.basicConfig(filename="mytechmint-logfile.log", level=logging.INFO)

There are a number of different levels that you can use to write to the file, such as:

logging.info('your text goes here')
logging.error('your text goes here')
logging.debug('your text goes here')

ReplyQuote