Select to view content in your preferred language

Not Getting anything Back When Querying Server Logs Using ArcGIS API for Python

318
4
03-17-2025 09:39 AM
BHK
by
Occasional Contributor

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!

BHK_0-1742229286502.png

but I am able to access to log setting

 

BHK_1-1742229494741.png

 

printing out the `recent_logs` return this

 

BHK_0-1742229968583.png

while `start_time` is this

BHK_1-1742230070271.png

 

 

 

 

 Can you please let me know why this is happening and how I fix this?

 

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

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

 


... sort of retired...
0 Kudos
CodyPatterson
MVP Regular Contributor

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

BHK
by
Occasional Contributor

Thanks Cody! so what would be the side effects of changing the maxHistory  to 0? Is this a good idea on PROD?

0 Kudos
CodyPatterson
MVP Regular Contributor

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

0 Kudos