Log file not being written to when executing from bat

3382
3
Jump to solution
03-16-2022 07:02 AM
by Anonymous User
Not applicable

We have our python script ready to be scheduled nightly to refresh our legacy parcels feature class from the fabric.  Preparing the script to be run from windows task scheduler I created a simple .bat file that calls the python exe and passes the script.

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" "\\path to script\script.py

This morning I ran the script by double clicking the .bat file. The messages appeared in the command window leading me to believe that the log file would be updated.

The .py script uses logging library:

logging.basicConfig(filename='parcelsync.log', level=logging.DEBUG)

# Start Time
print ("\nStart Time: {}".format(StartTime))
logging.info("\nStart Time: {}".format(StartTime))

After the script completed I noticed that the log file hadn't been updated but the script did update the features.

What am I missing?

I tried searching the web for an explanation and I can't come close to finding a relevant result 🙂

As always, help is greatly appreciated.

1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor III

Perhaps the log file is ending up in a different directory. Try to specify the full log file path in the call to basicConfig to see if that helps.

View solution in original post

3 Replies
DonMorrison1
Occasional Contributor III

Perhaps the log file is ending up in a different directory. Try to specify the full log file path in the call to basicConfig to see if that helps.

by Anonymous User
Not applicable

You are correct! It was writing to the location of the bat file and not the python file which I had in a different location. Thank you.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

As Don said, you could put the full path to the log file in the filename= parameter.

 

out = r'C:\Python Scripts\Logfiles\log.txt'
logging.basicConfig(filename=out,level=logging.DEBUG)