4

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?

1
  • 1
    you need to turn the message level on the service itself to INFO | WARNING | ERROR to show applicable arcpy.Add__messages
    – KHibma
    Commented Sep 1, 2015 at 15:51

2 Answers 2

5

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):

enter image description here

2

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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.