---
title: "Jobs.QueryLogs"
description: "Query log records emitted while running a job."
image: "https://tilebox.com/images/tilebox-docs-social-preview.png"
---

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

# Jobs.QueryLogs

import { Fragment } from "astro/jsx-runtime";

import ApiReference from "@docs/components/ApiReference.astro";

import ParamField from "@docs/components/ParamField.astro";

```go
func (*JobClient) QueryLogs(
    ctx context.Context,
    jobID uuid.UUID,
    options ...job.TelemetryQueryOption,
) iter.Seq2[*workflows.LogRecord, error]
```

Query log records emitted while running a job.

The logs are lazily loaded and returned as a sequence of log records. Use [Collect](/docs/api-reference/go/workflows/Collect) to transform the sequence into a slice.

## Parameters

**jobID**

type: uuid.UUID

required: true

The ID of the job to query logs for.
**options**

type: []job.TelemetryQueryOption

Options for querying logs.

## Options

**job.WithCursor(cursor *job.Cursor)**

Start the query after the cursor returned by a previous page.
**job.WithLimit(limit int64)**

Limit the total number of log records yielded by the sequence.
**job.WithSortDirection(direction job.SortDirection)**

Sort logs by time. Use `job.Ascending` for oldest first or `job.Descending` for newest first.

## Returns

A sequence of log records. Each record includes `Time`, `SeverityText`, `Body`, trace IDs, span IDs, and structured attributes.

<h2 id="request-example">Usage example</h2>

```go
import (
    "fmt"
    "log/slog"
    "time"

    "github.com/google/uuid"
    "github.com/tilebox/tilebox-go/workflows/v1"
    "github.com/tilebox/tilebox-go/workflows/v1/job"
)

jobID := uuid.MustParse("019e07b1-916b-0630-f3ba-f1c33235d174")

for record, err := range client.Jobs.QueryLogs(
    ctx,
    jobID,
    job.WithSortDirection(job.Ascending),
) {
    if err != nil {
        slog.ErrorContext(
            ctx,
            "failed to query job logs",
            slog.Any("error", err),
        )
        return
    }

    fmt.Printf("%s %-5s %s\n",
        record.Time.Format(time.RFC3339),
        record.SeverityText,
        record.Body,
    )
}
```

Source: https://tilebox.com/docs/api-reference/go/workflows/Jobs.QueryLogs/index.mdx
