How to write a log file to a defined folder

2041
3
Jump to solution
09-24-2012 07:32 AM
SahasShrestha
New Contributor
I've written python code  for map automation. It is working currently. I like to see the log file of this tool and like to save it to some other directory. How do I write log file with username, date stamp and geo processing commands used to a defined folder in other directory. I appreciate your help. Thanks.
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Here's an example on how to write the current windows user and current date and time to a text file:

import getpass, datetime  f = open(r"C:\temp\python\logfile.txt", "a")  user = getpass.getuser() date = str(datetime.datetime.now())  f.write("Username:\t" + user + "\n") f.write("Date:\t" + date + "\n")  f.close()

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Here's an example on how to write the current windows user and current date and time to a text file:

import getpass, datetime  f = open(r"C:\temp\python\logfile.txt", "a")  user = getpass.getuser() date = str(datetime.datetime.now())  f.write("Username:\t" + user + "\n") f.write("Date:\t" + date + "\n")  f.close()
0 Kudos
SahasShrestha
New Contributor
This tool works perfectly well !! Thanks a lot.
0 Kudos
DuncanHornby
MVP Notable Contributor
If you want to get a lot more sophisticated with logging progress, you could use the Python logger module?
0 Kudos