---
title: "Custom logs"
description: "Step-by-step guide to configure Middleware integration for Custom Logs. Track application logs, detect errors, and monitor performance."
section: "API"
breadcrumb: "API > Custom Logs"
canonical: "https://docs.middleware.io/get-started/ingestion-api/custom-logs"
---
# Custom logs

If you want to send custom logs to the Middleware backend, you can use the provided API. This documentation covers how you can use the API to send the custom logs to the Middleware backend and how the data can be accessed via the Middleware dashboard.

## Before you begin

- Endpoint: `https://demo.middleware.io/v1/logs`
- Auth: pass your Middleware API key in the `Authorization` header.

## Endpoint

```bash
POST https://demo.middleware.io/v1/logs
```

## Authentication

Include your Middleware API Key in:

```bash
Authorization: your-initial-token
```

## Sample cURL

You can refer to this sample curl request to understand how to ingest custom logs to Middleware. Request Body fields are explained in the next section.

```bash
curl -X POST "https://demo.middleware.io/v1/logs" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: your-initial-token" \
  -d @- << 'EOF'
{
  "resource_logs": [
    {
      "resource": {
        "attributes": [
          { "key": "mw.resource_type", "value": { "string_value": "custom" } },
          { "key": "service.name",    "value": { "string_value": "nginx-123" } }
        ]
      },
      "scope_logs": [
        {
          "log_records": [
            {
              "severity_text": "WARN",
              "body": { "string_value": "upstream server is not accepting request" },
              "severity_number": 11,
              "attributes": [
                { "key": "server", "value": { "string_value": "nginx" } }
              ],
              "time_unix_nano": 1759750270000000000
            }
          ]
        }
      ]
    }
  ]
}
EOF
```

## Understanding resource attributes

`resource_logs → resource → attributes`

| Key | Compliance Level | Description |
| --- | --- | --- |
| `mw.account_key` | required | Will be required to authenticate your data with your Middleware account |
| `mw.resource_type` | required | Will be required to label the log source as `"custom"` |
| `service.name` | optional | Can be helpful to filter the data in the Logs module |

## Understanding log records

`resource_logs → scope_logs → log_records`

| Key | Compliance Level | Description |
| --- | --- | --- |
| `severity_text` | optional | One of FATAL, ERROR, WARN, INFO, DEBUG, TRACE |
| `severity_number` | optional | 1-4 : TRACE, 5-8 : DEBUG, 9-12 : INFO, 13-16 : WARN, 17-20 : ERROR, 21-24 : FATAL |
| `body` | required | The actual log body you want to ingest (`string_value`) |
| `time_unix_nano` | required | Timestamp for your log in nanoseconds since epoch |

## Verify delivery

Once you send data to the Middleware backend, you can access verify the data from the logs section. It can be further filtered using the custom attributes you have used in the cURL request.

For example, in the sample cURL request, we have used `mw.resource_type = custom`.

![Middleware Custom Logs API integration ](/images/v2/apm/custom-logs-api.webp)

## Troubleshooting

- 401/403 (auth): Use header exactly `Authorization: <YOUR_MW_API_KEY>` (no “Bearer”). Include `mw.account_key` in `resource.attributes` and ensure key/account match.
- 400 / schema issues: JSON must be valid. Required: `mw.account_key`, `mw.resource_type="custom"`, `body.string_value`, `time_unix_nano` (number). Keep exact casing (`string_value`, not `stringValue`).
- Logs not visible: `time_unix_nano` must be nanoseconds (≈19 digits), not ms. Widen the time range and start with filter `mw.resource_type=custom`; refine by `service.name` if needed.
- Severity looks off: Use `severity_text` from {FATAL, ERROR, WARN, INFO, DEBUG, TRACE}. Keep `severity_number` within documented bands.
- Batch too big / 413 / flakiness: Send smaller batches (e.g., 500–1000 log records) and add retry with exponential backoff for 429/timeouts.
- CORS/proxy/TLS hiccups: Call the endpoint from server/agent code (not browser). If behind a corporate proxy, trust its CA or bypass interception for `demo.middleware.io`.
- Endpoint/headers sanity check: `POST https://demo.middleware.io/v1/logs` with `Content-Type: application/json` and `Accept: application/json`.

Need assistance or want to learn more about Middleware? Get in touch with us via our Contact Us page or join our Slack channel.
