HOW TO
Sometimes, users get a repeated false positive log message or an unwanted log message from Portal for ArcGIS, ArcGIS Server, or ArcGIS Data Store and they would like to erase it from both the logs directory and the ArcGIS Server Manager or Portaladmin endpoints. This is to avoid the consumption of disk space in the logs directory as well as to be able to clearly see and focus on the important log messages.
This can be done by running a Python script that checks all the log files in a specified directory and deletes the lines that have a specified log message.
Let's say we want to automate the deletion of the following Portal for ArcGIS log message:
The web server was found to be stopped. Re-starting it.
Run the below Python script after you consider the following:
Please note that the below script will work on any IDLE utilizing any Python 3.x environment, including but not limited to ArcGIS Pro Python environments.
import os res = [] # SPECIFY PATH FOR LOGS path = r"C:\arcgisportal\logs" ##SPECIFY THE LOG YOU WOULD LIKE TO DELETE string = "The web server was found to be stopped. Re-starting it." ##CREATE A LIST OF ALL EXISTING .log FILE PATHS (DO NOT CHANGE) for (path, dir_names, file_names) in os.walk(path): for name in file_names: res.append(os.path.join(path, name)) ##FIND THE LINE THAT HAS THE LOG MESSAGE AND DELETE IT (DO NOT CHANGE) for file in res: try: with open(file, 'r') as f: replaced_content = "" for line in f: if string not in line: replaced_content += line f.close() f = open(file, "wt") f.write(replaced_content) f.close() except Exception as ex: print(ex) pass
The image below shows a typical log file before running the script that contains two instances of the message: "The web server was found to be stopped. Re-starting it.":
After running the script, instances this message are removed from the log file, as shown in the image below.
To schedule the Python script, run it as a task in Windows Task Scheduler. For more information, please refer to Schedule a Python script or model to run at a prescribed time: 2019 update.
Article ID: 000030692
Get help from ArcGIS experts
Download the Esri Support App