# log

Outputs a message to the Logs section of the Developer Console. Useful for debugging, tracking script execution, and monitoring variable values.

```liquid
{% log "Hello world!" %}
{% log order.name %}
{% log "Order total: " | append: order.total_price %}
```

#### Syntax

```liquid
{% log value %}
{% log value | filter %}
{% log "string" | append: variable %}
```

#### Parameters

| Parameter | Required | Description                                                   |
| --------- | -------- | ------------------------------------------------------------- |
| `value`   | Yes      | Any value to log - string, number, object, array, or variable |

#### Output Formatting

The log tag automatically formats output based on the value type:

| Value Type  | Output                          |
| ----------- | ------------------------------- |
| String      | Displayed as-is                 |
| Number      | Displayed as-is                 |
| Object      | JSON-formatted with indentation |
| Array       | JSON-formatted with indentation |
| `null`      | Displayed as "null"             |
| `undefined` | Displayed as "undefined"        |

#### Examples

**Log a simple message:**

```liquid
{% log "Script started" %}
```

**Log a variable:**

```liquid
{% log order %}
{% log customer.email %}
{% log line_items %}
```

**Log with appended values:**

```liquid
{% log "Processing order: " | append: order.name %}
{% log "Customer email: " | append: customer.email %}
{% log "Total items: " | append: order.line_items.size %}
```

**Log calculation results:**

```liquid
{% assign discount = order.total_price | times: 0.1 %}
{% log "Discount amount: " | append: discount %}
```

**Debug conditional logic:**

```liquid
{% if customer.orders_count > 10 %}
  {% log "VIP customer detected" %}
  {% assign is_vip = true %}
{% else %}
  {% log "Regular customer" %}
  {% assign is_vip = false %}
{% endif %}
```

**Log loop progress:**

```liquid
{% for item in order.line_items %}
  {% log "Processing item: " | append: item.title %}

  {% comment %} Process item... {% endcomment %}

  {% log "Item " | append: forloop.index | append: " of " | append: forloop.length | append: " complete" %}
{% endfor %}
```

**Log object properties:**

```liquid
{% log "Order ID: " | append: order.id %}
{% log "Order name: " | append: order.name %}
{% log "Created at: " | append: order.created_at %}
{% log "Financial status: " | append: order.financial_status %}
```

**Log entire objects for debugging:**

```liquid
{% comment %} Log full order object {% endcomment %}
{% log order %}

{% comment %} Log API response {% endcomment %}
{% http url: api_endpoint, method: "GET" as response %}
{% log response %}

{% comment %} Log GraphQL result {% endcomment %}
{% graphql query: my_query, variables: vars as result %}
{% log result %}
```

**Log array contents:**

```liquid
{% assign tags = product.tags | split: ", " %}
{% log "Product tags:" %}
{% log tags %}
```

**Track script execution flow:**

```liquid
{% log "=== Starting inventory sync ===" %}

{% log "Step 1: Fetching products..." %}
{% comment %} ... fetch logic ... {% endcomment %}

{% log "Step 2: Processing updates..." %}
{% comment %} ... update logic ... {% endcomment %}

{% log "Step 3: Sending notifications..." %}
{% comment %} ... notification logic ... {% endcomment %}

{% log "=== Inventory sync complete ===" %}
```

**Log with JSON filter for complex objects:**

```liquid
{% json payload %}
  {
    "order_id": {{ order.id }},
    "items": {{ order.line_items | map: "sku" | json }}
  }
{% endjson %}

{% log "Payload created:" %}
{% log payload %}
```

**Conditional logging:**

```liquid
{% if response.status != 200 %}
  {% log "API Error - Status: " | append: response.status %}
  {% log "Error body:" %}
  {% log response.body %}
{% endif %}
```

#### Notes

* Logs appear in the Logs section of the Developer Console
* Objects and arrays are automatically JSON-formatted with 2-space indentation
* Maximum log length is 20,000 characters - longer logs are truncated
* Supports Liquid filters for formatting (e.g., `| append:`, `| upcase`, `| date:`)
* No credit cost for logging
* Use logs liberally during development, consider reducing in production for cleaner output


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/tags/log.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
