Hi All,
Really simple script attached to a toolbox tool:
Zip file attached with script and toolbox. Here's the script:
import arcpy
import logging
class AddMessageHandler(logging.Handler):
def emit(self, record):
log_entry = self.format(record)
arcpy.AddMessage(log_entry)
def main():
logging.debug("----this is a test----")
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
root_logger = logging.getLogger()
root_logger.addHandler(AddMessageHandler())
main()
First run success:
Subsequent runs fail:
Works in Python 3.6.8 within ArcGIS Pro.
Are you using python 2.7?
In any event, give this a shot, which also worked flawlessly
import arcpy
import logging
class AddMessageHandler(logging.Handler):
def emit(self, record):
log_entry = self.format(record)
arcpy.AddMessage(log_entry)
def main():
logging.basicConfig(level=logging.DEBUG)
root_logger = logging.getLogger()
root_logger.addHandler(AddMessageHandler())
logging.debug("----this is a test----")
if __name__ == '__main__':
main()
Yes it's python 2.7, ArcGIS 10.6.1... ArcGIS Server does not support python 3.x, Pro is not an option.
Moving the logging lines does not change the result. Runs fine the first time, fails the every time after that.
Don't know the differences between the server version and *map or *pro. That leave python 2.7 or server or moving emit out of the class and just calling it