---
title: "Cloudflare Workers"
description: "Use the console-based Workers logger for request-scoped logs and manual request emission."
canonical_url: "https://www.blyp.dev/docs/integrations/workers"
markdown_url: "https://www.blyp.dev/docs/integrations/workers.md"
last_updated: "2018-10-20"
x_farming_labs_generated_preamble: true
---

# Cloudflare Workers
URL: /docs/integrations/workers
LLM index: /llms.txt
Description: Use the console-based Workers logger for request-scoped logs and manual request emission.

# Cloudflare Workers

Workers use a separate API from the Node/Bun server adapters.

```ts
import { initWorkersLogger, createWorkersLogger } from "@blyp/core/workers";

initWorkersLogger({
  env: { service: "my-worker" },
  customProps: (request) => ({
    requestId: request.headers.get("x-request-id"),
  }),
});

export default {
  async fetch(request: Request): Promise<Response> {
    const log = createWorkersLogger(request);

    log.set({ action: "handle_request" });
    log.info("worker started");

    const response = Response.json({ ok: true });
    log.emit({ response });

    return response;
  },
};
```

## Differences from the Node/Bun adapters

- no file logging
- no `blyp.config.json`
- no automatic client log ingestion
- console-based output only
- request logs are emitted manually through `emit()`

## Error emission

```ts
const log = createWorkersLogger(request);

try {
  // handler work
} catch (error) {
  log.emit({ error });
  throw error;
}
```

`emit()` returns the first emitted `HttpRequestLog` record and does not emit twice for the same request logger.

## What emitted request logs look like

When you call `emit({ response })`, Blyp writes request output like:

```text
[INFO]  GET  /health        200  2ms
[INFO]  POST /checkout      200  143ms
[INFO]  GET  /users/42      404  8ms
[ERROR] POST /payments      500  1203ms
```

Fields included automatically: method, path, status code, and duration.

**In production (NDJSON):**

```json
{"level":"info","time":1710000000000,"msg":"GET /health","type":"http_request","method":"GET","url":"/health","statusCode":200,"responseTime":2}
{"level":"info","time":1710000000001,"msg":"POST /checkout","type":"http_request","method":"POST","url":"/checkout","statusCode":200,"responseTime":143}
```

## Relevant types

```ts
import type {
  WorkersLoggerConfig,
  WorkersEmitOptions,
  WorkersRequestLogger,
} from "@blyp/core/workers";
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
