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

# Logs

> Monitorea tus funciones con jelou functions logs, ctx.log() para logging estructurado, y jelou functions cron logs para ejecuciones cron.

## Streaming en vivo

Por defecto, `jelou functions logs` hace streaming de logs en tiempo real:

```bash theme={null}
jelou functions logs mi-funcion
# ▸ Streaming logs for mi-funcion
# ▸ Press Ctrl+C to stop
#
#   10:30:01  INFO  Buscando cliente { telefono: "593987654321" }
#   10:30:02  WARN  API externa lenta { latency: 2300 }
#   10:31:15  INFO  Buscando cliente { telefono: "593912345678" }
```

La flag `--follow` / `-f` es equivalente (es el comportamiento por defecto):

```bash theme={null}
jelou functions logs mi-funcion --follow
```

## Logs históricos

Para obtener logs pasados en lugar de streaming:

```bash theme={null}
jelou functions logs mi-funcion --history
# ◇ Fetched 47 logs
#
#   10:25:01  INFO  Deployed successfully
#   10:30:01  INFO  Buscando cliente { telefono: "593987654321" }
#   10:30:02  WARN  API externa lenta { latency: 2300 }
```

## Escribir logs desde tu función

Usa `ctx.log()` dentro del handler para escribir logs estructurados:

```typescript theme={null}
handler: async (input, ctx) => {
  ctx.log("Procesando pedido", {
    telefono: input.telefono,
    company: ctx.company.id,
    requestId: ctx.requestId,
  });

  const resultado = await procesarPedido(input);

  ctx.log("Pedido completado", { resultado });

  return resultado;
}
```

`ctx.log()` escribe JSON estructurado a stdout:

```json theme={null}
{
  "requestId": "a1b2c3d4-...",
  "function": "mi-funcion",
  "company": 42,
  "timestamp": "2026-04-07T15:30:01.234Z",
  "args": ["Procesando pedido", { "telefono": "593987654321", "company": 42 }]
}
```

<Note>
  `console.log()`, `console.warn()` y `console.error()` también funcionan y son capturados por la plataforma, pero `ctx.log()` agrega metadatos útiles (requestId, function, company, timestamp) automáticamente.
</Note>

## Logs de cron

Para ver el historial de ejecuciones cron:

```bash theme={null}
jelou functions cron logs mi-funcion
# ◇ Found 12 log entries
#
# ▸ Time                    Tool       State       HTTP
# ▸ 4/7/2026, 9:00:00 AM   default    DELIVERED   200
# ▸ 4/7/2026, 3:00:00 AM   default    DELIVERED   200
# ▸ 4/6/2026, 9:00:00 AM   default    ERROR       500
```

### Filtrar por estado

```bash theme={null}
jelou functions cron logs mi-funcion --state ERROR
```

Estados posibles: `DELIVERED`, `ERROR`, `RETRY`, `RETRY_SCHEDULED`, `ACTIVE`, `FAILED`.

### Paginación

```bash theme={null}
jelou functions cron logs mi-funcion --cursor <cursor>
```

El cursor se muestra al final de la salida cuando hay más resultados disponibles.

## JSON mode

Para integrar con herramientas externas, usa `--json`:

```bash theme={null}
# Logs como JSON lines (streaming)
jelou functions logs mi-funcion --json

# Logs históricos como JSON
jelou functions logs mi-funcion --history --json

# Cron logs como JSON
jelou functions cron logs mi-funcion --json
```

<Tip>
  En CI/CD, combina `--json` con herramientas como `jq` para filtrar logs:

  ```bash theme={null}
  jelou functions logs mi-funcion --history --json | jq 'select(.level == "ERROR")'
  ```
</Tip>
