ExtractRESTLogs

Title  Extract Logs from REST

Description

Extracts logs from ArcGIS Server.

Usage

          
By default, all logs are extracted. This can be a time intensive process, so consider filtering by time and/or service name.
When you have access to the directory with the ArcGIS Server logs, it is typically faster to use ExtractFileLogs.

License

Standard

Syntax

ExtractRESTLogs (site, folder, {from_date}, {to_date}, {log_level}, {log_codes}, {process_ids}, {request_ids}, {components}, {services}, {machines})

Parameter Explanation Data Type
site Dialog Reference

The ArcGIS Server site to query.

GPString
folder Dialog Reference

The location to save the output.

DEFolder
from_date (Optional) Dialog Reference

The oldest time to include in the result set. If not specified, then all logs will be returned.

GPDate
to_date (Optional) Dialog Reference

The most recent time to query. If not specified, then the current time will be used.

GPDate
log_level (Optional) Dialog Reference

Only records with a log level at or more severe than this level are returned. If not specified, then WARNING will be used.

GPString
log_codes (Optional) Dialog Reference

Specifies the log codes assigned to server logs. If not specified, then all codes will be queried.

GPLong
process_ids (Optional) Dialog Reference

Specifies the machine process IDs to query. If not specified, then all process IDs will be queried.

GPLong
request_ids (Optional) Dialog Reference

Specifies an ID assigned to a specific server request. If not specified, then all request IDs will be queried.

GPString
components (Optional) Dialog Reference

Specifies the server components delivering the log message. If not specified, then all components will be queried.

GPString
services (Optional) Dialog Reference

Specifies whether to query all, none, or a specific service in your site. If not specified, then all services will be queried.

GPString
machines (Optional) Dialog Reference

Specifies whether to query all or a specific machine in your server site. If not specified, then all machines will be queried.

GPString

Code Samples

ExtractRESTLogs example 1 (Python window)

Extracts all the ArcGIS Server logs.

import arcpy

arcpy.udms.ExtractRESTLogs("https://acme.com/portal", "D:/data/logs")

ExtractRESTLogs example 2 (stand-alone script)

Extracts ArcGIS Server logs for a specific time period.

import datetime
import os

import arcpy

# The active portal connection will be used for log querying.
arcpy.SignInToPortal("https://acme.com/portal")

folder = "D:/data/logs"

# Yesterday's logs from 8 AM - 6 PM.
yesterday = datetime.date.today() - datetime.timedelta(days=1)
start = datetime.datetime.combine(yesterday, datetime.time(hour=8))
end = datetime.datetime.combine(yesterday, datetime.time(hour=18))

# Passing no filter is the same as passing everything.
result = arcpy.udms.ExtractRESTLogs(
    site=None,
    folder=folder,
    from_date=start,
    to_date=end,
    log_level="FINE",
    log_codes=[],
    process_ids=[],
    request_ids=[],
    components=[],
    services=[],
    machines=[],
)

logs = os.path.join(result[0], "logs")
count = arcpy.GetCount_management(logs)[0]
print(f"Extracted {int(count):,} log entries")