-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.ts
More file actions
39 lines (36 loc) · 1.16 KB
/
default.ts
File metadata and controls
39 lines (36 loc) · 1.16 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
/**
* @fileoverview Module-singleton owner for the shared default
* `Logger` instance. Kept in its own leaf so that callers who only
* need the singleton (`getDefaultLogger()`) don't drag in the full
* `Logger` class symbol table when tree-shaking; `core.ts` exports
* the constructor for callers that need their own instance.
*
* Construction is lazy so that importing this module during early
* Node.js bootstrap doesn't try to resolve `node:console` before
* stdout is ready (mirrors the lazy `Console` init inside `Logger`
* itself).
*/
import { Logger } from './core'
let _logger: Logger | undefined
/**
* Get the default logger instance.
* Lazily creates the logger to avoid circular dependencies during module initialization.
* Reuses the same instance across calls.
*
* @returns Shared default logger instance
*
* @example
* ```ts
* import { getDefaultLogger } from '@socketsecurity/lib/logger/default'
*
* const logger = getDefaultLogger()
* logger.log('Application started')
* logger.success('Configuration loaded')
* ```
*/
export function getDefaultLogger(): Logger {
if (_logger === undefined) {
_logger = new Logger()
}
return _logger
}