Published geoprocessing services write logs that are available at ArcGis Server Manager (arcgis-server/arcgis/manager/log.html
)
Arcpy has AddMessage
, AddError
, etc methods for logging, but they are doesn't works when script is published as geoprocessing service. As I understand, they works only locally in ArcMap.
Is there some way to write server logs from arcpy?
-
1you need to turn the message level on the service itself to INFO | WARNING | ERROR to show applicable arcpy.Add__messagesKHibma– KHibma2015年09月01日 15:51:49 +00:00Commented Sep 1, 2015 at 15:51
2 Answers 2
If you use the arcpy.AddMessage(message)
, it should show up in your published GP, but it shows up on the job messages page (not the server logs as you indicated in your question). You also need to enable this in the service properties (or when you publish the service):
The AddMessage
will add a message to the geoprocessing job message queue:
enter image description here
jobs/ja861064b634648f1be2371e2307c6112?f=json
For general logging, I use python logging:
import logging
and make sure the formatter has a process id:
formatter = logging.Formatter('%(asctime)s p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s |-| %(message)s')
# Set up logging
logfilepath = os.path.join(tempfile.gettempdir(),'example.log')
logger = logging.getLogger('example_logger')
logger.setLevel(logging.DEBUG)
logger.handlers = []
formatter = logging.Formatter('%(asctime)s p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s |-| %(message)s')
fh = logging.FileHandler(logfilepath)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.info('example script start...')
fh.flush()
logger.debug('Importing ArcPy...')
import arcpy
logger.debug('Importing ArcPy Import Complete')
Explore related questions
See similar questions with these tags.