Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing a log file from python program

Tags:

python

logging

I want to output some strings to a log file and I want the log file to be continuously updated.

I have looked into the logging module pf python and found out that it is mostly about formatting and concurrent access.

Please let me know if I am missing something or amy other way of doing it

like image 788
Shan Avatar asked Mar 18 '13 10:03

Shan


1 Answers

To add my 10cents with regards to using logging. I've only recently discovered the Logging module and was put off at first. Maybe just because it initially looks like a lot of work, but it's really simple and incredibly handy.

This is the set up that I use. Similar to Mkinds answer, but includes a timestamp.

# Set up logging
log = "bot.log"
logging.basicConfig(filename=log,level=logging.DEBUG,format='%(asctime)s %(message)s', datefmt='%d/%m/%Y %H:%M:%S')
logging.info('Log Entry Here.')

Which will produce something like:

22/09/2015 14:39:34 Log Entry Here.
like image 128
FredFury Avatar answered Oct 12 '22 06:10

FredFury