logging

द्वारा cloudflare

लॉग जोड़ने, डीबग करने, या SDK और कंटेनर रनटाइम में Logger के साथ काम करने पर उपयोग करें। इसमें कंस्ट्रक्टर-इंजेक्शन पैटर्न, चाइल्ड लॉगर आदि शामिल हैं।

npx skills add https://github.com/cloudflare/sandbox-sdk --skill logging

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:

VarValuesPurpose
SANDBOX_LOG_LEVELdebug | info | warn | errorMinimum level emitted
SANDBOX_LOG_FORMATjson | prettyOutput 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

cloudflare की और Skills

workerd-api-review
cloudflare
कार्य प्रदर्शन अनुकूलन, API डिज़ाइन और अनुकूलता, सुरक्षा कमज़ोरियाँ, और workerd कोड समीक्षा के लिए मानक विनिर्देश अनुपालन। tcmalloc-जागरूक को शामिल करता है…
official
workerd-safety-review
cloudflare
मेमोरी सुरक्षा, थ्रेड सुरक्षा, समवर्तीता, और workerd कोड समीक्षा के लिए महत्वपूर्ण पहचान पैटर्न। V8/KJ सीमा खतरे, जीवनकाल प्रबंधन को शामिल करता है,…
official
module-registry
cloudflare
जब workerd में मॉड्यूल रजिस्ट्री के साथ काम कर रहे हों — मॉड्यूल रिज़ॉल्यूशन, संकलन, मूल्यांकन या पंजीकरण को पढ़ना, संशोधित करना, डीबग करना या समीक्षा करना — तब लोड करें।
official
reproduce
cloudflare
क्लाउडफ्लेयर/एजेंट्स गिटहब इश्यू को पुनः उत्पन्न करने के लिए एक न्यूनतम एजेंट्स/वर्कर प्रोजेक्ट तैयार करें और इसे एक अस्थायी क्लाउडफ्लेयर खाते में डिप्लॉय करें, फिर रिपोर्ट करें…
official
local-explorer
cloudflare
स्थानीय एक्सप्लोरर या स्थानीय API में उत्पादों/संसाधनों को कैसे जोड़ें। नए स्थानीय APIs या UI रूट्स को लागू करते समय उपयोग करें...
official
commit-categories
cloudflare
चेंजलॉग और "नया क्या है" सारांश के लिए कमिट वर्गीकरण नियम। चेंजलॉग या व्हाट्स-न्यू कमांड में कमिट को वर्गीकृत करने से पहले लोड किया जाना चाहिए। प्रदान करता है…
official
architecture
cloudflare
कोडबेस में पहली बार नेविगेट करते समय, नया क्लाइंट मेथड जोड़ते समय, नया कंटेनर हैंडलर/सर्विस जोड़ते समय, या यह समझने के लिए उपयोग करें कि अनुरोध कैसे प्रवाहित होता है…
official
changesets
cloudflare
चेंजसेट बनाते समय, रिलीज़ तैयार करते समय, या वर्ज़न अपडेट करते समय उपयोग करें। इसमें शामिल है कि किन पैकेजों का संदर्भ लेना है, उपयोगकर्ता-सामने वाले चेंजसेट विवरण कैसे लिखने हैं,…
official