mcpbeat

Logging

cloudflare/logging

Use when adding logs, debugging, or working with the Logger across the SDK and container runtime. Covers the constructor-injection pattern, child loggers, env-var configuration, and test mocking. (project)

556 tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
1089
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/cloudflare/sandbox-sdk --skill logging

The instruction itself

6 sections, as written by the author

Logging

Pattern: Explicit Constructor Injection

Loggers are passed explicitly via constructor injection throughout the codebase. There is no global/ambient logger.

import type { Logger } from '@repo/shared';

class MyService {
  constructor(private logger: Logger) {}

  async doWork(context: WorkContext) {
    const childLogger = this.logger.child({ operation: 'work' });
    childLogger.info('Working', { context });
  }
}

Child loggers

Use logger.child({ ... }) to attach structured context that will appear on every log line from that child. Prefer child loggers at the boundary of a unit of work (request, operation, session) rather than re-passing context on every call.

Configuration

Two environment variables, both read once at startup:

| Var | Values | Purpose |

| -------------------- | -------------------------------------- | --------------------- |

| SANDBOX_LOG_LEVEL | debug \| info \| warn \| error | Minimum level emitted |

| SANDBOX_LOG_FORMAT | json \| pretty | Output format |

Use json in production (machine-parseable) and pretty for local dev.

In Tests

Use createNoOpLogger() from @repo/shared to silence logging in tests:

import { createNoOpLogger } from '@repo/shared';

const service = new MyService(createNoOpLogger());

Don't construct real loggers in unit tests — they add noise and can mask real failures with log output.

When Adding Logs

  • Log at info for significant lifecycle events (operation started/completed)
  • Log at debug for fine-grained tracing (request bodies, intermediate state)
  • Log at warn for recoverable anomalies
  • Log at error for failures that surface to the caller; include the error object as structured context: logger.error('Failed', { err })
  • Pass structured context as the second argument, not via string interpolation

How to use it

Copy the folder

Take cloudflare/logging from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.