-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
47 lines (44 loc) · 1.39 KB
/
Copy pathlogger.ts
File metadata and controls
47 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Logger interface — injected into core functions so consumers control
* where log output goes (stdout, VS Code OutputChannel, structured JSON, etc.).
*
* @sentinel-scan/core NEVER calls console.* directly. It always uses this interface.
* If no logger is provided, noopLogger is used (silent).
*/
export interface Logger {
debug(message: string, meta?: Record<string, unknown>): void
info(message: string, meta?: Record<string, unknown>): void
warn(message: string, meta?: Record<string, unknown>): void
error(message: string, meta?: Record<string, unknown>): void
}
/**
* A no-operation logger used as the default when no logger is injected.
* Silent by design — consumers opt in to logging.
*/
export const noopLogger: Logger = {
debug: () => undefined,
info: () => undefined,
warn: () => undefined,
error: () => undefined,
}
/**
* Creates a Logger that prefixes every message with a scope tag.
* Useful for composing loggers in the runner when calling sub-systems.
*/
export function scopedLogger(logger: Logger, scope: string): Logger {
const prefix = `[${scope}] `
return {
debug: (msg, meta) => {
logger.debug(prefix + msg, meta)
},
info: (msg, meta) => {
logger.info(prefix + msg, meta)
},
warn: (msg, meta) => {
logger.warn(prefix + msg, meta)
},
error: (msg, meta) => {
logger.error(prefix + msg, meta)
},
}
}