> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get logs

> Retrieve the logs of the latest search and indexing operations.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Retrieve log entries" href="/doc/libraries/sdk/methods/search/get-logs" />

**Required ACL:** `logs`

Logs are kept for up to seven days and limited to 1,000 per server.
You can't access logs after the retention period ends.

This API method counts towards your operation quota but isn't logged.

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  // Get last 10 log entries
  client.GetLogs();

  // Asynchronous
  await client.GetLogsAsync();

  // Get last 100 log entries
  client.GetLogs(offset: 0, length: 100);

  // Asynchronous
  await client.GetLogsAsync(offset: 0, length: 100);
  ```

  ```go Go theme={"system"}
  // Gets last 10 log entries
  params := []interface{}{
    "offset": 0,
    "length": 10,
    "type":   "query",
  }
  res, err := client.GetLogs(params)

  // Gets last 100 log entries
  params["length"] = 100
  res, err = client.GetLogs(params)

  // Gets last 100 log errors
  params["type"] = "error"
  res, err = client.GetLogs(params)
  ```

  ```java Java theme={"system"}
  // Get last 10 log entries
  client.getLogs();

  // Get last 100 log entries, of type build
  client.getLogs(0, 100);

  // Asynchronous
  client.getLogsAsync();
  client.getLogsAsync(0, 100);
  ```

  ```js JavaScript theme={"system"}
  client.getLogs({
    offset: 100, // where to start from, default to 0
    length: 100, // how many lines you want, default to 10
    type: 'error' // which logs you want, default to no value (all)
  }).then(({ logs }) => {
    console.log(logs);
  });
  ```

  ```kotlin Kotlin theme={"system"}
  client.getLogs(page = 0, hitsPerPage = 100)
  ```

  ```php PHP theme={"system"}
  // Get last 10 log entries
  $res = $client->getLogs();

  // Get last 100 log entries
  $res = $client->getLogs([
    'offset' => 0,
    'length' => 100
  ]);
  ```

  ```python Python theme={"system"}
  # Get last 10 log entries
  print(client.get_logs())
  # Get last 100 log entries
  print(client.get_logs({
      'offset': 0,
      'length': 100
  }))
  ```

  ```ruby Ruby theme={"system"}
  # Get last 10 log entries
  logs = client.get_logs

  # Get last 100 log entries
  logs = client.get_logs({ offset: 0, length: 100 })

  # Get last 100 errors
  logs = client.get_logs({ offset: 0, length: 100, type: 'error' })
  ```

  ```scala Scala theme={"system"}
  // Get last 10 log entries
  client.execute {
     getLogs
  }

  // Get last 100 log entries
  client.execute {
     getLogs length 100
  }
  ```

  ```swift Swift theme={"system"}
  client.getLogs(offset: 0,
                 length: 10,
                 type: .query) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="length" type="integer" default={10}>
  The maximum number of entries to retrieve starting at the offset.
  Maximum allowed value: 1,000.
</ParamField>

<ParamField body="offset" type="integer" default={0}>
  Specify the first entry to retrieve (with 0 being the most recent log entry).
  The maximum offset is the total number of stored logs (which can be lower than the maximum of 1,000).
</ParamField>

<ParamField body="requestOptions" type="object">
  A mapping of request options to send along with the request.
</ParamField>

<ParamField body="type" type="enum<string>">
  Type of logs to retrieve. One of:

  * `all`: Retrieve all the logs.
  * `query`: Retrieve only the queries.
  * `build`: Retrieve only the build operations.
  * `error`: Retrieve only the errors.
</ParamField>

## Response

<ResponseField name="answer" type="string">
  Answer body. It's truncated after 1000 characters.
</ResponseField>

<ResponseField name="answer_code" type="string">
  HTTP response code.
</ResponseField>

<ResponseField name="exhaustive" type="boolean">
  Exhaustive flags used during the query.
</ResponseField>

<ResponseField name="index" type="string">
  Index name of the log.
</ResponseField>

<ResponseField name="inner_queries" type="object[]">
  Contains an object for each performed query with the `indexName`, `queryID`, `offset`, and `userToken`.
</ResponseField>

<ResponseField name="ip" type="string">
  Client ip of the call.
</ResponseField>

<ResponseField name="method" type="string">
  Rest type of the method.
</ResponseField>

<ResponseField name="nb_api_calls" type="string">
  Number of API calls.
</ResponseField>

<ResponseField name="processing_time_ms" type="string">
  Processing time for the query. This does not include network time.
</ResponseField>

<ResponseField name="query_body" type="string">
  Request body. It's truncated after 1000 characters.
</ResponseField>

<ResponseField name="query_headers" type="string">
  Request Headers (API Key is obfuscated).
</ResponseField>

<ResponseField name="query_nb_hits" type="string">
  Number of hits returned for the query.
</ResponseField>

<ResponseField name="sha1" type="string">
  SHA1 ID of entry.
</ResponseField>

<ResponseField name="timestamp" type="string">
  Timestamp in ISO-8601 format.
</ResponseField>

<ResponseField name="url" type="string">
  Request URL.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "logs":[
      {
        "timestamp":"2017-12-29T18:15:57Z",
        "method":"POST",
        "answer_code":"200",
        "query_body":"\n{\n \"requests\": [\n  {\n   \"indexName\": \"best_buy\",\n   \"params\": \"query=&hitsPerPage=10&page=0&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%22brand%22%2C%22categories%22%2C%22free_shipping%22%2C%22type%22%5D&tagFilters=\"\n  }\n ]\n}\n",
        "answer":"\n{\n \"results\": [\n  {\n   \"hits\": [\n    {\n     \"name\": \"Amazon - Fire TV Stick\",\n     \"description\": \"Amazon Fire TV Stick connects to your TV's HDMI port. Just grab and go to enjoy Netflix, Prime Instant Video, Hulu Plus, YouTube.com, music, and much more.\",\n     \"brand\": \"Amazon\",\n     \"categories\": [\n      \"TV & Home Theater\",\n      \"Streaming Media Players\"\n     ],\n     \"hierarchicalCategories\": {\n      \"lvl0\": \"TV & Home Theater\",\n      \"lvl1\": \"TV & Home Theater > Streaming Media Players\"\n     },\n     \"type\": \"Streaming media plyr\",\n     \"price\": 39.99,\n     \"price_range\": \"1 - 50\",\n     \"image\": \"https:\/\/cdn-demo.algolia.com\/bestbuy\/9999119_sb.jpg\",\n     \"url\": \"http:\/\/www.bestbuy.com\/site\/amazon-fire-tv-stick\/9999119.p?id=1219460752591&skuId=9999119&cmp=RMX&ky=1uWSHMdQqBeVJB9cXgEke60s5EjfS6M1W\",\n     \"free_shipping\": false,\n     \"popularity\": 9843,\n     \"rating\": 4,\n     \"objectID\": \"9999119\"\n",
        "url":"\/1\/indexes\/*\/queries?x-algolia-agent=Algolia%20for%20vanilla%20JavaScript%203.24.7%3BAlgolia%20Dashboard%201.0.0%3Breact-instantsearch%204.1.3%3BJS%20Helper%202.23.0&x-algolia-application-id=AJ0P3S7DWQ&x-algolia-api-key=ce11****************************",
        "ip":"84.14.205.82",
        "query_headers":"Host: c1-de-3.algolianet.com\nConnection: keep-alive\nContent-Length: 308\naccept: application\/json\nOrigin: https:\/\/www.algolia.com\nUser-Agent: Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/63.0.3239.84 Safari\/537.36\ncontent-type: application\/x-www-form-urlencoded\nReferer: https:\/\/www.algolia.com\/apps\/AJ0P3S7DWQ\/explorer\/browse\/best_buy\nAccept-Encoding: gzip, deflate, br\nAccept-Language: fr,en;q=0.9\n",
        "sha1":"44c168cea54d2deca9a4724559cf15eccf15cf3e",
        "nb_api_calls":"1",
        "processing_time_ms":"1",
        "query_nb_hits":"10500",
        "index":"demo_index",
        "inner_queries":[
            {
              "indexName":"best_buy",
              "queryID":313453231,
              "offset":0,
              "userToken":"user_1"
            }
        ]
      }
  ]
}
```
