HTTP APIs
Query log entries using the Logging REST API with Service Account authentication and filter expressions.
Read time 2 minutesLast updated 18 hours ago
You can query the Logging service by using a REST API. The logs endpoint is authenticated using Unity Service Accounts.
Requesting logs
Make a GET request to the Logging API.- The Observability API documentation contains a detailed description of operations for querying logs.
- Refer to Authentication for more information on how to authenticate.
The following optional query parameters are available:curl https://services.api.unity.com/observability/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/logs \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \--url-query 'from=<TIME_FROM>' \--url-query 'to=<TIME_TO>' \--url-query 'query=<FILTER_EXPRESSION>' \--url-query 'limit=<LIMIT>' \--url-query 'offset=<OFFSET>'
- : a RFC3339 timestamp used to specify the starting timestamp of the records to return. For example,
from.2023-06-29T11:30:22.939Z - : a RFC3339 timestamp used to specify the ending timestamp of the records to return.
to - : a boolean expression for filtering. Refer to Filter logs for more information.
query - : a positive integer to serve as the maximum number of records to return. Must be less than or equal to 100.
limit - : a positive integer to serve as the offset number of logs from the first result of the query.
offset
Relative time ranges
The API also supports relative time expressions for the from and to parameters to make working with time ranges easier. The basic syntax of consists of the following components:- Base time: Either an RFC3999 timestamp or the keyword.
now - Operator: Either + or -.
- Time offset: An integer and a unit for days, hours, minutes, or seconds, e.g. 12d, 5h, 3m, 17s.
- from=now-30m
- from=2023-08-29T11:30:00.000Z+30s
- from=now-2d&to=now-6h
Example API call
The following example shows how to query logs from the Logging API using cURL. Refer to Authentication for more information on how to authenticate.The response could look as follows:curl https://services.api.unity.com/observability/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/logs \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \--url-query 'from=2023-09-01T00:00:00.000Z' \--url-query 'to=2023-09-01T13:50:00.000Z' \--url-query 'query=body~=”regular” AND logAttributes.example.myKey=”foo”' \--url-query 'limit=10' \--url-query 'offset=0'
The response contains the following fields:{ "limit" : 10, "offset" : 0, "total" : 600, "results" : [ { "severityNumber" : 9, "severityText" : "Information", "timestamp" : "2023-09-01T10:45:00.445Z", "body" : "this is just a regular log message", "logAttributes" : { "example.myKey" : "foo", "log.record.uid" : "a566701a-a9e5-42f7-bd8e-013fa9ef1afa", "unity.environmentId" : "c288f9e5-423b-4150-a982-5a1a40b1219a", "unity.projectId" : "2af24fd0-f224-499e-8768-07b54c693aee" }, "resourceAttributes" : { "service.name" : "cloud-code" } } ]}
- : the maximum number of records returned.
limit - : the offset number of logs from the first result of the query.
offset - : the total number of records that match the query.
total - : an array of log entries.
results
results