<commit_before>---
post_title: Logging API Examples
feature_maturity: preview
menu_order: 4
---

This topic provides common usage examples for the Logging API.

**Prerequisites:**

- [Bash](https://www.gnu.org/software/bash/)
- [Curl](https://curl.haxx.se/)
- [jq](https://stedolan.github.io/jq/)
- [DC/OS](/docs/1.9/installing/)
- [DC/OS CLI](/docs/1.9/cli/) must be installed, configured, and logged in.
- Extract `DCOS_URL` and `DCOS_AUTH_TOKEN` from the DC/OS CLI:

    ```
    DCOS_URL="$(dcos config show core.dcos_url)"
    DCOS_URL="${DCOS_URL%/}" # strip trailing slash, if present
    DCOS_AUTH_TOKEN="$(dcos config show core.dcos_acs_token)"
    ```

# Node Logs

Get the last 100 journal entries from a single node:

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/logs/v1/range/?skip_prev=100"
```

# Component Logs

Get the last 100 journal entries from a single component service:

**Leading Mesos Master:**

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/leader/mesos/logs/v1/range/?skip_prev=100&filter=_SYSTEMD_UNIT:dcos-mesos-master.service"
```

**Leading Marathon:**

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/leader/marathon/logs/v1/range/?skip_prev=100&filter=_SYSTEMD_UNIT:dcos-mesos-master.service"
```

**Agent DNS Forwarder (Spartan):**

```
# select an agent ID
AGENT_ID="$(dcos node --json | jq -r '.[0].id)')"
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/agent/${AGENT_ID}/logs/v1/range/?skip_prev=1&filter=_SYSTEMD_UNIT:dcos-spartan.service"
```

# Container Logs

Get the last 100 journal entries from a single service container:

```
FRAMEWORK_NAME="marathon"
APP_ID="nginx"

# get the mesos task state json
MESOS_STATE="$(curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" ${DCOS_URL}/mesos/state)"
TASK_STATE="$(echo "${MESOS_STATE}" | jq ".frameworks[] | select(.name == \"${FRAMEWORK_NAME}\") | .tasks[] | select(.name == \"${APP_ID}\")")"

# extract values from the task json
AGENT_ID="$(echo "${TASK_STATE}" | jq -r '.slave_id')"
TASK_ID="$(echo "${TASK_STATE}" | jq -r '.id')"
FRAMEWORK_ID="$(echo "${TASK_STATE}" | jq -r '.framework_id')"
EXECUTOR_ID="$(echo "${TASK_STATE}" | jq -r '.executor_id')"
CONTAINER_ID="$(echo "${TASK_STATE}" | jq -r '.statuses[0].container_status.container_id.value')"

# default to container ID when executor ID is empty
EXECUTOR_ID="${EXECUTOR_ID:-${TASK_ID}}"

# get container/task logs
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/agent/${AGENT_ID}/logs/v1/range/framework/${FRAMEWORK_ID}/executor/${EXECUTOR_ID}/container/${CONTAINER_ID}?skip_prev=100"
```

**Important:**
Journald task logging is disabled in DC/OS 1.9.0. For more information, see [Logging API: Compatibility]()/docs/1.9/monitoring/logging/logging-api/#compatibility).

# Tail
<commit_msg>Fix Logging API: Compatibility link<commit_after>---
post_title: Logging API Examples
feature_maturity: preview
menu_order: 4
---

This topic provides common usage examples for the Logging API.

**Prerequisites:**

- [Bash](https://www.gnu.org/software/bash/)
- [Curl](https://curl.haxx.se/)
- [jq](https://stedolan.github.io/jq/)
- [DC/OS](/docs/1.9/installing/)
- [DC/OS CLI](/docs/1.9/cli/) must be installed, configured, and logged in.
- Extract `DCOS_URL` and `DCOS_AUTH_TOKEN` from the DC/OS CLI:

    ```
    DCOS_URL="$(dcos config show core.dcos_url)"
    DCOS_URL="${DCOS_URL%/}" # strip trailing slash, if present
    DCOS_AUTH_TOKEN="$(dcos config show core.dcos_acs_token)"
    ```

# Node Logs

Get the last 100 journal entries from a single node:

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/logs/v1/range/?skip_prev=100"
```

# Component Logs

Get the last 100 journal entries from a single component service:

**Leading Mesos Master:**

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/leader/mesos/logs/v1/range/?skip_prev=100&filter=_SYSTEMD_UNIT:dcos-mesos-master.service"
```

**Leading Marathon:**

```
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/leader/marathon/logs/v1/range/?skip_prev=100&filter=_SYSTEMD_UNIT:dcos-mesos-master.service"
```

**Agent DNS Forwarder (Spartan):**

```
# select an agent ID
AGENT_ID="$(dcos node --json | jq -r '.[0].id)')"
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/agent/${AGENT_ID}/logs/v1/range/?skip_prev=1&filter=_SYSTEMD_UNIT:dcos-spartan.service"
```

# Container Logs

Get the last 100 journal entries from a single service container:

```
FRAMEWORK_NAME="marathon"
APP_ID="nginx"

# get the mesos task state json
MESOS_STATE="$(curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" ${DCOS_URL}/mesos/state)"
TASK_STATE="$(echo "${MESOS_STATE}" | jq ".frameworks[] | select(.name == \"${FRAMEWORK_NAME}\") | .tasks[] | select(.name == \"${APP_ID}\")")"

# extract values from the task json
AGENT_ID="$(echo "${TASK_STATE}" | jq -r '.slave_id')"
TASK_ID="$(echo "${TASK_STATE}" | jq -r '.id')"
FRAMEWORK_ID="$(echo "${TASK_STATE}" | jq -r '.framework_id')"
EXECUTOR_ID="$(echo "${TASK_STATE}" | jq -r '.executor_id')"
CONTAINER_ID="$(echo "${TASK_STATE}" | jq -r '.statuses[0].container_status.container_id.value')"

# default to container ID when executor ID is empty
EXECUTOR_ID="${EXECUTOR_ID:-${TASK_ID}}"

# get container/task logs
curl -k -H "Authorization: token=${DCOS_AUTH_TOKEN}" "${DCOS_URL}/system/v1/agent/${AGENT_ID}/logs/v1/range/framework/${FRAMEWORK_ID}/executor/${EXECUTOR_ID}/container/${CONTAINER_ID}?skip_prev=100"
```

**Important:**
Journald task logging is disabled in DC/OS 1.9.0. For more information, see [Logging API: Compatibility](/docs/1.9/monitoring/logging/logging-api/#compatibility).

# Tail

{'fraction_non_alphanumeric': 0.186630005155525, 'fraction_numerical': 0.015122873345935728, 'mean_word_length': 5.224598930481283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6978187', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2150, 'n_words': 456}