Skip to content

Commit d4cee5e

Browse files
Clean up unused logging infrastructure (#234)
* Remove unused AsyncLocalStorage infrastructure The AsyncLocalStorage infrastructure (loggerStorage, getLogger, runWithLogger) was set up but never actually used. The codebase uses explicit logger passing via constructor injection throughout. This change removes the unused code, simplifies the logging module, and documents the explicit passing pattern as the canonical approach. The pattern works well for all scenarios including request context, background operations, lifecycle events, and long-lived objects. No breaking changes as the removed functions were never called. * Add changeset for logging cleanup * Fix e2e test worker template configuration Use 'vars' instead of 'env' for environment variables in wrangler template.
1 parent 3aba9e8 commit d4cee5e

File tree

10 files changed

+121
-288
lines changed

10 files changed

+121
-288
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudflare/sandbox': patch
3+
---
4+
5+
Remove unused logging infrastructure (getLogger, runWithLogger) that was never called

CLAUDE.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,22 @@ shared package for consistency across the SDK.
331331

332332
### Logging
333333

334-
- Centralized logger from `@repo/shared`
335-
- Structured logging with component context
336-
- Configurable via `SANDBOX_LOG_LEVEL` and `SANDBOX_LOG_FORMAT` env vars
334+
**Pattern**: Explicit logger passing via constructor injection throughout the codebase.
335+
336+
```typescript
337+
class MyService {
338+
constructor(private logger: Logger) {}
339+
340+
async doWork() {
341+
const childLogger = this.logger.child({ operation: 'work' });
342+
childLogger.info('Working', { context });
343+
}
344+
}
345+
```
346+
347+
**Configuration**: `SANDBOX_LOG_LEVEL` (debug|info|warn|error) and `SANDBOX_LOG_FORMAT` (json|pretty) env vars, read at startup.
348+
349+
**Testing**: Use `createNoOpLogger()` from `@repo/shared` in tests.
337350

338351
### Session Management
339352

package-lock.json

Lines changed: 15 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sandbox-container/src/config.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/**
2-
* Log level for the sandbox container.
3-
*
4-
* Default: info
5-
* Environment variable: SANDBOX_LOG_LEVEL
6-
*/
7-
const SANDBOX_LOG_LEVEL = process.env.SANDBOX_LOG_LEVEL || 'info';
8-
9-
/**
10-
* Log format for the sandbox container.
11-
*
12-
* Default: json
13-
* Set to "pretty" to enable colored, human-readable output.
14-
* Environment variable: SANDBOX_LOG_FORMAT
15-
*/
16-
const SANDBOX_LOG_FORMAT = process.env.SANDBOX_LOG_FORMAT || 'json';
17-
181
/**
192
* How long to wait for an interpreter process to spawn and become ready.
203
* If an interpreter doesn't start within this time, something is fundamentally
@@ -82,8 +65,6 @@ const STREAM_CHUNK_DELAY_MS = 100;
8265
const DEFAULT_CWD = '/workspace';
8366

8467
export const CONFIG = {
85-
SANDBOX_LOG_LEVEL,
86-
SANDBOX_LOG_FORMAT,
8768
INTERPRETER_SPAWN_TIMEOUT_MS,
8869
INTERPRETER_EXECUTION_TIMEOUT_MS,
8970
COMMAND_TIMEOUT_MS,

0 commit comments

Comments
 (0)