Skip to content

Commit 55ec7c7

Browse files
Copilotpelikhan
andcommitted
Use createLogger helper from logging.ts in documentation
- Add createLogger() helper function to logging.ts - Update all documentation examples to use createLogger instead of directly importing debug - Maintains namespace pattern 'mcp:<name>' internally - Addresses feedback to use helper function from logging.ts Co-authored-by: pelikhan <[email protected]>
1 parent bcc41aa commit 55ec7c7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

AGENTS.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ maintain consistency across the codebase.
8686
**Example:**
8787

8888
```typescript
89-
import debug from 'debug'
89+
import { createLogger } from './logging.js'
9090

9191
// Create a dedicated logger for this file
92-
const log = debug('mcp:server')
92+
const log = createLogger('server')
9393

9494
// Use the logger throughout your code
9595
log('Starting MCP proxy')
@@ -168,8 +168,8 @@ log('API key (first 8 chars): %s...', apiKey?.substring(0, 8) || 'not set')
168168

169169
When adding new functionality:
170170

171-
1. Import `debug` at the top of your file
172-
2. Create a dedicated logger instance with a unique namespace
171+
1. Import `createLogger` from `./logging.js` at the top of your file
172+
2. Create a dedicated logger instance with a unique name for your file
173173
3. Add log statements at key execution points:
174174
- Function entry points
175175
- Before/after important operations
@@ -181,9 +181,9 @@ When adding new functionality:
181181
**Example pattern:**
182182

183183
```typescript
184-
import debug from 'debug'
184+
import { createLogger } from './logging.js'
185185

186-
const log = debug('mcp:myfile')
186+
const log = createLogger('myfile')
187187

188188
export async function myFunction(param: string): Promise<void> {
189189
log('myFunction called with param: %s', param)

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/logging.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ export function setupDebugLogging(logDir: string): debug.Debugger {
1616
log(`Logging to ${logfile}`)
1717
return log
1818
}
19+
20+
/**
21+
* Create a logger for a specific file/component.
22+
* @param name - The name of the file/component (e.g., 'server', 'docker', 'port')
23+
* @returns A debug logger instance with namespace 'mcp:<name>'
24+
*/
25+
export function createLogger(name: string): debug.Debugger {
26+
return debug(`mcp:${name}`)
27+
}

0 commit comments

Comments
 (0)