I am using a ArcPy tool update some feature in ArcGIS desktop, also generating a log file to update some of the tasks, the script running fine in the desktop. When publishing it as a service to call the same from ArcGIS server, the log file is not created in the given path, but the process was completed successfully and the results are updated. What would be the correct way for creating a log file(or any other file) from a geoprocessing service?
File based outputs of GP services will be written to the scratch directory by design: C:\arcgisserver\directories\arcgisjobs\<service>\<jobID>\
You can write the log to that directory using the arcpy.env.scratchFolder environment variable:
logPath = os.path.join(arcpy.env.scratchFolder,"gplog.log")
This is challenging as you then need to know the job ID of the job to retrieve the results. You may be able to write to a table in a database, though. What do you need the log file for? What if you just return messages within the script:
arcpy.AddMessage("Successfully <did whatever>")
If you set the GP service to return Info messages, the client will be able to retrieve the messages.
Thanks for your suggestions guys. I couldn't make that work but my workaround is migrating the arcpy file itself to arcgis server instead of publishing it as a service. Now it's working fine and the log file is also created successfully.