I am trying to get ArcGIS Server logs using ArcGIS API for Python form this page
https://developers.arcgis.com/python/latest/guide/managing-your-gis-servers/
I am using this code
import datetime
import pandas as pd
now = datetime.datetime.now()
start_time = now - datetime.timedelta(days=10)
recent_logs = server1.logs.query(start_time = start_time)
#print a message as a sample
recent_logs['logMessages'][0]
but I am not getting anything!
but I am able to access to log setting
printing out the `recent_logs` return this
while `start_time` is this
Can you please let me know why this is happening and how I fix this?
In your image, logMessages is an empty list, hence the index error message
recent_logs['logMessages'][0]
from the recent_logs dictionary with the 'logMessages' key, it is empty so trying to get the first (that is [0] )
will return a key.
To avoid the error you would have to check its length, then if there any, get the first
msgs = recent_logs['logMessages']
msgs = recent_logs['logMessages']
if len(msgs) > 0:
first = msgs[0]
print("first message {}".format(first))
else:
print("no messages")
Hey @BHK
I know this may not be the entire answer, but something that I noticed. In your screenshot of the working logs.settings, it states that your maxHistory is 1, which means that it is only keeping the logs for 1 single day. You may try sorting the logs instead of within 10 days, to 10 hours/1 day to see if it's pulling anything correctly. I'll continue looking through to see if there's anything I can test on my side to get this replicated!
Cody
Thanks Cody! so what would be the side effects of changing the maxHistory to 0? Is this a good idea on PROD?
Hey @BHK
Changing maxHistory to 0 will cause all history to be indefinitely kept, this may be negligible space now, but may result in a significant amount of data being held after a long while. Depending on your log settings, if they log at the Info or Debug, you could end up with hundreds or thousands a day.
I would personally set the history time at 15, maybe even 30, to keep 15 and 30 days. That would be my recommendation, and I have mine set up to 30 in prod!
Cody