@geekmidas/logger 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -7
- package/dist/console.cjs +75 -17
- package/dist/console.cjs.map +1 -1
- package/dist/console.d.cts +31 -7
- package/dist/console.d.mts +31 -7
- package/dist/console.mjs +76 -18
- package/dist/console.mjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/pino.cjs +42 -1
- package/dist/pino.cjs.map +1 -1
- package/dist/pino.d.cts +23 -3
- package/dist/pino.d.mts +23 -3
- package/dist/pino.mjs +42 -2
- package/dist/pino.mjs.map +1 -1
- package/dist/redact-paths-Br-tI2GZ.d.cts +18 -0
- package/dist/redact-paths-CIsuxHH7.d.mts +18 -0
- package/dist/redact-paths-D0m0DIuQ.cjs +73 -0
- package/dist/redact-paths-D0m0DIuQ.cjs.map +1 -0
- package/dist/redact-paths-DQoIXhkS.mjs +67 -0
- package/dist/redact-paths-DQoIXhkS.mjs.map +1 -0
- package/dist/redact-paths.cjs +3 -0
- package/dist/redact-paths.d.cts +2 -0
- package/dist/redact-paths.d.mts +2 -0
- package/dist/redact-paths.mjs +3 -0
- package/dist/{types-C1RfRbo6.d.mts → types-Bga8WDuP.d.mts} +86 -2
- package/dist/{types-DXdmn7h5.d.cts → types-JxCFymH0.d.cts} +86 -2
- package/dist/types-ag_0Cvbg.cjs.map +1 -1
- package/dist/types-yQ6XOihF.mjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/package.json +10 -1
- package/src/__tests__/console.spec.ts +277 -140
- package/src/__tests__/pino-redaction.integration.spec.ts +307 -0
- package/src/__tests__/pino.spec.ts +199 -0
- package/src/console.ts +95 -23
- package/src/index.ts +1 -0
- package/src/pino.ts +105 -2
- package/src/redact-paths.ts +71 -0
- package/src/types.ts +87 -0
package/README.md
CHANGED
|
@@ -4,13 +4,12 @@ A simple and flexible structured logging library for Node.js and browsers with c
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- ✅ **Zero Dependencies**: No external dependencies
|
|
7
|
+
- **Standard Interface**: Common logger interface with multiple log levels (debug, info, warn, error, fatal, trace)
|
|
8
|
+
- **Structured Logging**: Support for both structured (object + message) and simple (message only) logging
|
|
9
|
+
- **Child Loggers**: Create child loggers with inherited context
|
|
10
|
+
- **Multiple Implementations**: ConsoleLogger for simple use, PinoLogger for production
|
|
11
|
+
- **Sensitive Data Redaction**: Built-in redaction for passwords, tokens, API keys, and more
|
|
12
|
+
- **TypeScript**: Full TypeScript support with type-safe logging
|
|
14
13
|
|
|
15
14
|
## Installation
|
|
16
15
|
|
|
@@ -38,6 +37,114 @@ logger.info('Application started');
|
|
|
38
37
|
logger.error({ error, operation: 'fetchUser' }, 'Failed to fetch user');
|
|
39
38
|
```
|
|
40
39
|
|
|
40
|
+
## Pino Logger
|
|
41
|
+
|
|
42
|
+
For production use, the package provides a Pino-based logger with high performance and built-in redaction support.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createLogger } from '@geekmidas/logger/pino';
|
|
46
|
+
|
|
47
|
+
const logger = createLogger({
|
|
48
|
+
level: 'info',
|
|
49
|
+
pretty: true, // Pretty printing in development
|
|
50
|
+
redact: true, // Enable sensitive data redaction
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
logger.info({ userId: 123 }, 'User logged in');
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Sensitive Data Redaction
|
|
57
|
+
|
|
58
|
+
The Pino logger includes built-in redaction to automatically mask sensitive data like passwords, tokens, and API keys.
|
|
59
|
+
|
|
60
|
+
### Enable with Defaults
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { createLogger } from '@geekmidas/logger/pino';
|
|
64
|
+
|
|
65
|
+
const logger = createLogger({ redact: true });
|
|
66
|
+
|
|
67
|
+
// Sensitive data is automatically masked
|
|
68
|
+
logger.info({ password: 'secret123', user: 'john' }, 'Login attempt');
|
|
69
|
+
// Output: { password: '[Redacted]', user: 'john' } Login attempt
|
|
70
|
+
|
|
71
|
+
logger.info({ headers: { authorization: 'Bearer xyz' } }, 'Request');
|
|
72
|
+
// Output: { headers: { authorization: '[Redacted]' } } Request
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Default Redacted Fields
|
|
76
|
+
|
|
77
|
+
When `redact: true`, the following fields are automatically masked:
|
|
78
|
+
|
|
79
|
+
- **Authentication**: `password`, `pass`, `passwd`, `secret`, `token`, `accessToken`, `refreshToken`, `apiKey`, `api_key`, `authorization`, `credentials`
|
|
80
|
+
- **Headers**: `headers.authorization`, `headers.cookie`, `headers["x-api-key"]`
|
|
81
|
+
- **Personal Data**: `ssn`, `creditCard`, `cardNumber`, `cvv`, `pin`
|
|
82
|
+
- **Secrets**: `connectionString`, `databaseUrl`
|
|
83
|
+
- **Wildcards**: `*.password`, `*.secret`, `*.token` (catches nested fields)
|
|
84
|
+
|
|
85
|
+
### Add Custom Paths (Merged with Defaults)
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const logger = createLogger({
|
|
89
|
+
redact: ['user.ssn', 'payment.cardNumber'],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Both custom paths AND defaults are redacted
|
|
93
|
+
logger.info({ password: 'secret', user: { ssn: '123-45-6789' } }, 'Data');
|
|
94
|
+
// Output: { password: '[Redacted]', user: { ssn: '[Redacted]' } } Data
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Override Defaults
|
|
98
|
+
|
|
99
|
+
Use `resolution: 'override'` to disable default paths and use only your custom paths:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const logger = createLogger({
|
|
103
|
+
redact: {
|
|
104
|
+
paths: ['myCustomSecret'],
|
|
105
|
+
resolution: 'override',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Only 'myCustomSecret' is redacted, defaults are ignored
|
|
110
|
+
logger.info({ password: 'visible', myCustomSecret: 'hidden' }, 'Data');
|
|
111
|
+
// Output: { password: 'visible', myCustomSecret: '[Redacted]' } Data
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Custom Censor and Remove
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// Custom censor string
|
|
118
|
+
const logger = createLogger({
|
|
119
|
+
redact: {
|
|
120
|
+
paths: ['secret'],
|
|
121
|
+
censor: '***HIDDEN***',
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Remove fields entirely instead of masking
|
|
126
|
+
const logger2 = createLogger({
|
|
127
|
+
redact: {
|
|
128
|
+
paths: ['temporaryData'],
|
|
129
|
+
remove: true,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Path Syntax
|
|
135
|
+
|
|
136
|
+
Redaction paths support dot notation and wildcards:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
redact: [
|
|
140
|
+
'password', // Top-level field
|
|
141
|
+
'user.password', // Nested field
|
|
142
|
+
'users[*].password', // Array wildcard
|
|
143
|
+
'*.secret', // Any object's 'secret' field
|
|
144
|
+
'headers["x-api-key"]', // Bracket notation for special chars
|
|
145
|
+
]
|
|
146
|
+
```
|
|
147
|
+
|
|
41
148
|
## API Reference
|
|
42
149
|
|
|
43
150
|
### Logger Interface
|
package/dist/console.cjs
CHANGED
|
@@ -1,45 +1,83 @@
|
|
|
1
|
+
const require_types = require('./types-ag_0Cvbg.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/console.ts
|
|
4
|
+
/**
|
|
5
|
+
* Numeric priority for log levels (higher = more severe)
|
|
6
|
+
*/
|
|
7
|
+
const LOG_LEVEL_PRIORITY = {
|
|
8
|
+
[require_types.LogLevel.Trace]: 10,
|
|
9
|
+
[require_types.LogLevel.Debug]: 20,
|
|
10
|
+
[require_types.LogLevel.Info]: 30,
|
|
11
|
+
[require_types.LogLevel.Warn]: 40,
|
|
12
|
+
[require_types.LogLevel.Error]: 50,
|
|
13
|
+
[require_types.LogLevel.Fatal]: 60,
|
|
14
|
+
[require_types.LogLevel.Silent]: 70
|
|
15
|
+
};
|
|
3
16
|
var ConsoleLogger = class ConsoleLogger {
|
|
17
|
+
level;
|
|
4
18
|
/**
|
|
5
19
|
* Creates a new ConsoleLogger instance.
|
|
6
20
|
*
|
|
7
21
|
* @param data - Initial context data to include in all log messages
|
|
22
|
+
* @param level - Minimum log level to output (default: Info)
|
|
8
23
|
*/
|
|
9
|
-
constructor(data = {}) {
|
|
24
|
+
constructor(data = {}, level = require_types.LogLevel.Info) {
|
|
10
25
|
this.data = data;
|
|
26
|
+
this.level = level;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a log level should be output based on the configured minimum level.
|
|
30
|
+
*/
|
|
31
|
+
shouldLog(level) {
|
|
32
|
+
if (this.level === require_types.LogLevel.Silent) return false;
|
|
33
|
+
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.level];
|
|
11
34
|
}
|
|
12
35
|
/**
|
|
13
36
|
* Creates a logging function that merges context data and adds timestamps.
|
|
14
37
|
*
|
|
15
38
|
* @param logMethod - The console method to use (e.g., console.log, console.error)
|
|
39
|
+
* @param level - The log level for this method
|
|
16
40
|
* @returns A LogFn that handles both structured and simple logging
|
|
17
41
|
* @private
|
|
18
42
|
*/
|
|
19
|
-
createLogFn(logMethod) {
|
|
20
|
-
return (
|
|
43
|
+
createLogFn(logMethod, level) {
|
|
44
|
+
return (objOrMsg, msg, ...args) => {
|
|
45
|
+
if (!this.shouldLog(level)) return;
|
|
21
46
|
const ts = Date.now();
|
|
22
|
-
|
|
47
|
+
if (typeof objOrMsg === "string") {
|
|
48
|
+
const logData$1 = {
|
|
49
|
+
...this.data,
|
|
50
|
+
msg: objOrMsg,
|
|
51
|
+
ts
|
|
52
|
+
};
|
|
53
|
+
logMethod(logData$1, ...args);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const logData = msg ? {
|
|
57
|
+
...this.data,
|
|
58
|
+
...objOrMsg,
|
|
59
|
+
msg,
|
|
60
|
+
ts
|
|
61
|
+
} : {
|
|
23
62
|
...this.data,
|
|
24
|
-
...
|
|
63
|
+
...objOrMsg,
|
|
25
64
|
ts
|
|
26
65
|
};
|
|
27
|
-
|
|
28
|
-
else logMethod(mergedData, ...args);
|
|
66
|
+
logMethod(logData, ...args);
|
|
29
67
|
};
|
|
30
68
|
}
|
|
69
|
+
/** Trace level logging function */
|
|
70
|
+
trace = this.createLogFn(console.trace.bind(console), require_types.LogLevel.Trace);
|
|
31
71
|
/** Debug level logging function */
|
|
32
|
-
debug = this.createLogFn(console.debug.bind(console));
|
|
72
|
+
debug = this.createLogFn(console.debug.bind(console), require_types.LogLevel.Debug);
|
|
33
73
|
/** Info level logging function */
|
|
34
|
-
info = this.createLogFn(console.info.bind(console));
|
|
74
|
+
info = this.createLogFn(console.info.bind(console), require_types.LogLevel.Info);
|
|
35
75
|
/** Warning level logging function */
|
|
36
|
-
warn = this.createLogFn(console.warn.bind(console));
|
|
76
|
+
warn = this.createLogFn(console.warn.bind(console), require_types.LogLevel.Warn);
|
|
37
77
|
/** Error level logging function */
|
|
38
|
-
error = this.createLogFn(console.error.bind(console));
|
|
78
|
+
error = this.createLogFn(console.error.bind(console), require_types.LogLevel.Error);
|
|
39
79
|
/** Fatal level logging function (uses console.error) */
|
|
40
|
-
fatal = this.createLogFn(console.error.bind(console));
|
|
41
|
-
/** Trace level logging function */
|
|
42
|
-
trace = this.createLogFn(console.trace.bind(console));
|
|
80
|
+
fatal = this.createLogFn(console.error.bind(console), require_types.LogLevel.Fatal);
|
|
43
81
|
/**
|
|
44
82
|
* Creates a child logger with additional context data.
|
|
45
83
|
* The child logger inherits all context from the parent and adds its own.
|
|
@@ -59,7 +97,7 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
59
97
|
return new ConsoleLogger({
|
|
60
98
|
...this.data,
|
|
61
99
|
...obj
|
|
62
|
-
});
|
|
100
|
+
}, this.level);
|
|
63
101
|
}
|
|
64
102
|
};
|
|
65
103
|
/**
|
|
@@ -67,14 +105,14 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
67
105
|
* ```typescript
|
|
68
106
|
* const logger = new ConsoleLogger({ app: 'myApp' });
|
|
69
107
|
* logger.info({ action: 'start' }, 'Application starting');
|
|
70
|
-
* // Logs: { app: 'myApp', action: 'start', ts: 1234567890 }
|
|
108
|
+
* // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
|
|
71
109
|
* ```
|
|
72
110
|
*
|
|
73
111
|
* @example Child logger usage
|
|
74
112
|
* ```typescript
|
|
75
113
|
* const childLogger = logger.child({ module: 'auth' });
|
|
76
114
|
* childLogger.debug({ userId: 123 }, 'User authenticated');
|
|
77
|
-
* // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 }
|
|
115
|
+
* // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
|
|
78
116
|
* ```
|
|
79
117
|
*
|
|
80
118
|
* @example Error logging with context
|
|
@@ -87,8 +125,28 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
87
125
|
* ```
|
|
88
126
|
*/
|
|
89
127
|
const DEFAULT_LOGGER = new ConsoleLogger();
|
|
128
|
+
/**
|
|
129
|
+
* Creates a console logger with the same API as pino's createLogger.
|
|
130
|
+
*
|
|
131
|
+
* @param options - Logger configuration options
|
|
132
|
+
* @returns A ConsoleLogger instance
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { createLogger } from '@geekmidas/logger/console';
|
|
137
|
+
* import { LogLevel } from '@geekmidas/logger';
|
|
138
|
+
*
|
|
139
|
+
* const logger = createLogger({ level: LogLevel.Debug });
|
|
140
|
+
* logger.debug('This will be logged');
|
|
141
|
+
* logger.trace('This will NOT be logged (below Debug level)');
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function createLogger(options = {}) {
|
|
145
|
+
return new ConsoleLogger({}, options.level ?? require_types.LogLevel.Info);
|
|
146
|
+
}
|
|
90
147
|
|
|
91
148
|
//#endregion
|
|
92
149
|
exports.ConsoleLogger = ConsoleLogger;
|
|
93
150
|
exports.DEFAULT_LOGGER = DEFAULT_LOGGER;
|
|
151
|
+
exports.createLogger = createLogger;
|
|
94
152
|
//# sourceMappingURL=console.cjs.map
|
package/dist/console.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.cjs","names":["data: object","logMethod: (...args: any[]) => void","
|
|
1
|
+
{"version":3,"file":"console.cjs","names":["LOG_LEVEL_PRIORITY: Record<LogLevel, number>","LogLevel","data: object","level: LogLevel","logMethod: (...args: any[]) => void","objOrMsg: T | string","msg?: string","logData","obj: object","options: CreateLoggerOptions"],"sources":["../src/console.ts"],"sourcesContent":["import type { CreateLoggerOptions, LogFn, Logger } from './types';\nimport { LogLevel } from './types';\n\n/**\n * Numeric priority for log levels (higher = more severe)\n */\nconst LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {\n [LogLevel.Trace]: 10,\n [LogLevel.Debug]: 20,\n [LogLevel.Info]: 30,\n [LogLevel.Warn]: 40,\n [LogLevel.Error]: 50,\n [LogLevel.Fatal]: 60,\n [LogLevel.Silent]: 70,\n};\n\nexport class ConsoleLogger implements Logger {\n private readonly level: LogLevel;\n\n /**\n * Creates a new ConsoleLogger instance.\n *\n * @param data - Initial context data to include in all log messages\n * @param level - Minimum log level to output (default: Info)\n */\n constructor(\n readonly data: object = {},\n level: LogLevel = LogLevel.Info,\n ) {\n this.level = level;\n }\n\n /**\n * Checks if a log level should be output based on the configured minimum level.\n */\n private shouldLog(level: LogLevel): boolean {\n if (this.level === LogLevel.Silent) {\n return false;\n }\n return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.level];\n }\n\n /**\n * Creates a logging function that merges context data and adds timestamps.\n *\n * @param logMethod - The console method to use (e.g., console.log, console.error)\n * @param level - The log level for this method\n * @returns A LogFn that handles both structured and simple logging\n * @private\n */\n private createLogFn(\n logMethod: (...args: any[]) => void,\n level: LogLevel,\n ): LogFn {\n return <T extends object>(\n objOrMsg: T | string,\n msg?: string,\n ...args: any[]\n ): void => {\n if (!this.shouldLog(level)) {\n return;\n }\n\n const ts = Date.now();\n\n // Handle simple string logging: logger.info('message')\n if (typeof objOrMsg === 'string') {\n const logData = { ...this.data, msg: objOrMsg, ts };\n logMethod(logData, ...args);\n return;\n }\n\n // Handle structured logging: logger.info({ data }, 'message')\n const logData = msg\n ? { ...this.data, ...objOrMsg, msg, ts }\n : { ...this.data, ...objOrMsg, ts };\n logMethod(logData, ...args);\n };\n }\n\n /** Trace level logging function */\n trace: LogFn = this.createLogFn(console.trace.bind(console), LogLevel.Trace);\n /** Debug level logging function */\n debug: LogFn = this.createLogFn(console.debug.bind(console), LogLevel.Debug);\n /** Info level logging function */\n info: LogFn = this.createLogFn(console.info.bind(console), LogLevel.Info);\n /** Warning level logging function */\n warn: LogFn = this.createLogFn(console.warn.bind(console), LogLevel.Warn);\n /** Error level logging function */\n error: LogFn = this.createLogFn(console.error.bind(console), LogLevel.Error);\n /** Fatal level logging function (uses console.error) */\n fatal: LogFn = this.createLogFn(console.error.bind(console), LogLevel.Fatal);\n\n /**\n * Creates a child logger with additional context data.\n * The child logger inherits all context from the parent and adds its own.\n *\n * @param obj - Additional context data for the child logger\n * @returns A new ConsoleLogger instance with merged context\n *\n * @example\n * ```typescript\n * const parentLogger = new ConsoleLogger({ app: 'myApp' });\n * const childLogger = parentLogger.child({ module: 'database' });\n * childLogger.info({ query: 'SELECT * FROM users' }, 'Query executed');\n * // Context includes both { app: 'myApp' } and { module: 'database' }\n * ```\n */\n child(obj: object): Logger {\n return new ConsoleLogger(\n {\n ...this.data,\n ...obj,\n },\n this.level,\n );\n }\n}\n\n/**\n * @example Basic usage\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp' });\n * logger.info({ action: 'start' }, 'Application starting');\n * // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }\n * ```\n *\n * @example Child logger usage\n * ```typescript\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ userId: 123 }, 'User authenticated');\n * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }\n * ```\n *\n * @example Error logging with context\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * logger.error({ error, operation: 'someOperation' }, 'Operation failed');\n * }\n * ```\n */\n\nexport const DEFAULT_LOGGER = new ConsoleLogger() as any;\n\n/**\n * Creates a console logger with the same API as pino's createLogger.\n *\n * @param options - Logger configuration options\n * @returns A ConsoleLogger instance\n *\n * @example\n * ```typescript\n * import { createLogger } from '@geekmidas/logger/console';\n * import { LogLevel } from '@geekmidas/logger';\n *\n * const logger = createLogger({ level: LogLevel.Debug });\n * logger.debug('This will be logged');\n * logger.trace('This will NOT be logged (below Debug level)');\n * ```\n */\nexport function createLogger(options: CreateLoggerOptions = {}): Logger {\n return new ConsoleLogger({}, options.level ?? LogLevel.Info);\n}\n"],"mappings":";;;;;;AAMA,MAAMA,qBAA+C;EAClDC,uBAAS,QAAQ;EACjBA,uBAAS,QAAQ;EACjBA,uBAAS,OAAO;EAChBA,uBAAS,OAAO;EAChBA,uBAAS,QAAQ;EACjBA,uBAAS,QAAQ;EACjBA,uBAAS,SAAS;AACpB;AAED,IAAa,gBAAb,MAAa,cAAgC;CAC3C,AAAiB;;;;;;;CAQjB,YACWC,OAAe,CAAE,GAC1BC,QAAkBF,uBAAS,MAC3B;EAFS;AAGT,OAAK,QAAQ;CACd;;;;CAKD,AAAQ,UAAUE,OAA0B;AAC1C,MAAI,KAAK,UAAUF,uBAAS,OAC1B,QAAO;AAET,SAAO,mBAAmB,UAAU,mBAAmB,KAAK;CAC7D;;;;;;;;;CAUD,AAAQ,YACNG,WACAD,OACO;AACP,SAAO,CACLE,UACAC,KACA,GAAG,SACM;AACT,QAAK,KAAK,UAAU,MAAM,CACxB;GAGF,MAAM,KAAK,KAAK,KAAK;AAGrB,cAAW,aAAa,UAAU;IAChC,MAAMC,YAAU;KAAE,GAAG,KAAK;KAAM,KAAK;KAAU;IAAI;AACnD,cAAUA,WAAS,GAAG,KAAK;AAC3B;GACD;GAGD,MAAM,UAAU,MACZ;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;IAAK;GAAI,IACtC;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;GAAI;AACrC,aAAU,SAAS,GAAG,KAAK;EAC5B;CACF;;CAGD,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAEN,uBAAS,MAAM;;CAE5E,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAEA,uBAAS,MAAM;;CAE5E,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,EAAEA,uBAAS,KAAK;;CAEzE,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,EAAEA,uBAAS,KAAK;;CAEzE,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAEA,uBAAS,MAAM;;CAE5E,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAEA,uBAAS,MAAM;;;;;;;;;;;;;;;;CAiB5E,MAAMO,KAAqB;AACzB,SAAO,IAAI,cACT;GACE,GAAG,KAAK;GACR,GAAG;EACJ,GACD,KAAK;CAER;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA2BD,MAAa,iBAAiB,IAAI;;;;;;;;;;;;;;;;;AAkBlC,SAAgB,aAAaC,UAA+B,CAAE,GAAU;AACtE,QAAO,IAAI,cAAc,CAAE,GAAE,QAAQ,SAASR,uBAAS;AACxD"}
|
package/dist/console.d.cts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
import { LogFn, Logger } from "./types-
|
|
1
|
+
import { CreateLoggerOptions, LogFn, LogLevel, Logger } from "./types-JxCFymH0.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/console.d.ts
|
|
4
4
|
declare class ConsoleLogger implements Logger {
|
|
5
5
|
readonly data: object;
|
|
6
|
+
private readonly level;
|
|
6
7
|
/**
|
|
7
8
|
* Creates a new ConsoleLogger instance.
|
|
8
9
|
*
|
|
9
10
|
* @param data - Initial context data to include in all log messages
|
|
11
|
+
* @param level - Minimum log level to output (default: Info)
|
|
10
12
|
*/
|
|
11
|
-
constructor(data?: object);
|
|
13
|
+
constructor(data?: object, level?: LogLevel);
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a log level should be output based on the configured minimum level.
|
|
16
|
+
*/
|
|
17
|
+
private shouldLog;
|
|
12
18
|
/**
|
|
13
19
|
* Creates a logging function that merges context data and adds timestamps.
|
|
14
20
|
*
|
|
15
21
|
* @param logMethod - The console method to use (e.g., console.log, console.error)
|
|
22
|
+
* @param level - The log level for this method
|
|
16
23
|
* @returns A LogFn that handles both structured and simple logging
|
|
17
24
|
* @private
|
|
18
25
|
*/
|
|
19
26
|
private createLogFn;
|
|
27
|
+
/** Trace level logging function */
|
|
28
|
+
trace: LogFn;
|
|
20
29
|
/** Debug level logging function */
|
|
21
30
|
debug: LogFn;
|
|
22
31
|
/** Info level logging function */
|
|
@@ -27,8 +36,6 @@ declare class ConsoleLogger implements Logger {
|
|
|
27
36
|
error: LogFn;
|
|
28
37
|
/** Fatal level logging function (uses console.error) */
|
|
29
38
|
fatal: LogFn;
|
|
30
|
-
/** Trace level logging function */
|
|
31
|
-
trace: LogFn;
|
|
32
39
|
/**
|
|
33
40
|
* Creates a child logger with additional context data.
|
|
34
41
|
* The child logger inherits all context from the parent and adds its own.
|
|
@@ -51,14 +58,14 @@ declare class ConsoleLogger implements Logger {
|
|
|
51
58
|
* ```typescript
|
|
52
59
|
* const logger = new ConsoleLogger({ app: 'myApp' });
|
|
53
60
|
* logger.info({ action: 'start' }, 'Application starting');
|
|
54
|
-
* // Logs: { app: 'myApp', action: 'start', ts: 1234567890 }
|
|
61
|
+
* // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
|
|
55
62
|
* ```
|
|
56
63
|
*
|
|
57
64
|
* @example Child logger usage
|
|
58
65
|
* ```typescript
|
|
59
66
|
* const childLogger = logger.child({ module: 'auth' });
|
|
60
67
|
* childLogger.debug({ userId: 123 }, 'User authenticated');
|
|
61
|
-
* // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 }
|
|
68
|
+
* // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
|
|
62
69
|
* ```
|
|
63
70
|
*
|
|
64
71
|
* @example Error logging with context
|
|
@@ -71,6 +78,23 @@ declare class ConsoleLogger implements Logger {
|
|
|
71
78
|
* ```
|
|
72
79
|
*/
|
|
73
80
|
declare const DEFAULT_LOGGER: any;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a console logger with the same API as pino's createLogger.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Logger configuration options
|
|
85
|
+
* @returns A ConsoleLogger instance
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { createLogger } from '@geekmidas/logger/console';
|
|
90
|
+
* import { LogLevel } from '@geekmidas/logger';
|
|
91
|
+
*
|
|
92
|
+
* const logger = createLogger({ level: LogLevel.Debug });
|
|
93
|
+
* logger.debug('This will be logged');
|
|
94
|
+
* logger.trace('This will NOT be logged (below Debug level)');
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function createLogger(options?: CreateLoggerOptions): Logger;
|
|
74
98
|
//#endregion
|
|
75
|
-
export { ConsoleLogger, DEFAULT_LOGGER };
|
|
99
|
+
export { ConsoleLogger, DEFAULT_LOGGER, createLogger };
|
|
76
100
|
//# sourceMappingURL=console.d.cts.map
|
package/dist/console.d.mts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
import { LogFn, Logger } from "./types-
|
|
1
|
+
import { CreateLoggerOptions, LogFn, LogLevel, Logger } from "./types-Bga8WDuP.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/console.d.ts
|
|
4
4
|
declare class ConsoleLogger implements Logger {
|
|
5
5
|
readonly data: object;
|
|
6
|
+
private readonly level;
|
|
6
7
|
/**
|
|
7
8
|
* Creates a new ConsoleLogger instance.
|
|
8
9
|
*
|
|
9
10
|
* @param data - Initial context data to include in all log messages
|
|
11
|
+
* @param level - Minimum log level to output (default: Info)
|
|
10
12
|
*/
|
|
11
|
-
constructor(data?: object);
|
|
13
|
+
constructor(data?: object, level?: LogLevel);
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a log level should be output based on the configured minimum level.
|
|
16
|
+
*/
|
|
17
|
+
private shouldLog;
|
|
12
18
|
/**
|
|
13
19
|
* Creates a logging function that merges context data and adds timestamps.
|
|
14
20
|
*
|
|
15
21
|
* @param logMethod - The console method to use (e.g., console.log, console.error)
|
|
22
|
+
* @param level - The log level for this method
|
|
16
23
|
* @returns A LogFn that handles both structured and simple logging
|
|
17
24
|
* @private
|
|
18
25
|
*/
|
|
19
26
|
private createLogFn;
|
|
27
|
+
/** Trace level logging function */
|
|
28
|
+
trace: LogFn;
|
|
20
29
|
/** Debug level logging function */
|
|
21
30
|
debug: LogFn;
|
|
22
31
|
/** Info level logging function */
|
|
@@ -27,8 +36,6 @@ declare class ConsoleLogger implements Logger {
|
|
|
27
36
|
error: LogFn;
|
|
28
37
|
/** Fatal level logging function (uses console.error) */
|
|
29
38
|
fatal: LogFn;
|
|
30
|
-
/** Trace level logging function */
|
|
31
|
-
trace: LogFn;
|
|
32
39
|
/**
|
|
33
40
|
* Creates a child logger with additional context data.
|
|
34
41
|
* The child logger inherits all context from the parent and adds its own.
|
|
@@ -51,14 +58,14 @@ declare class ConsoleLogger implements Logger {
|
|
|
51
58
|
* ```typescript
|
|
52
59
|
* const logger = new ConsoleLogger({ app: 'myApp' });
|
|
53
60
|
* logger.info({ action: 'start' }, 'Application starting');
|
|
54
|
-
* // Logs: { app: 'myApp', action: 'start', ts: 1234567890 }
|
|
61
|
+
* // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
|
|
55
62
|
* ```
|
|
56
63
|
*
|
|
57
64
|
* @example Child logger usage
|
|
58
65
|
* ```typescript
|
|
59
66
|
* const childLogger = logger.child({ module: 'auth' });
|
|
60
67
|
* childLogger.debug({ userId: 123 }, 'User authenticated');
|
|
61
|
-
* // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 }
|
|
68
|
+
* // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
|
|
62
69
|
* ```
|
|
63
70
|
*
|
|
64
71
|
* @example Error logging with context
|
|
@@ -71,6 +78,23 @@ declare class ConsoleLogger implements Logger {
|
|
|
71
78
|
* ```
|
|
72
79
|
*/
|
|
73
80
|
declare const DEFAULT_LOGGER: any;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a console logger with the same API as pino's createLogger.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Logger configuration options
|
|
85
|
+
* @returns A ConsoleLogger instance
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { createLogger } from '@geekmidas/logger/console';
|
|
90
|
+
* import { LogLevel } from '@geekmidas/logger';
|
|
91
|
+
*
|
|
92
|
+
* const logger = createLogger({ level: LogLevel.Debug });
|
|
93
|
+
* logger.debug('This will be logged');
|
|
94
|
+
* logger.trace('This will NOT be logged (below Debug level)');
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function createLogger(options?: CreateLoggerOptions): Logger;
|
|
74
98
|
//#endregion
|
|
75
|
-
export { ConsoleLogger, DEFAULT_LOGGER };
|
|
99
|
+
export { ConsoleLogger, DEFAULT_LOGGER, createLogger };
|
|
76
100
|
//# sourceMappingURL=console.d.mts.map
|
package/dist/console.mjs
CHANGED
|
@@ -1,44 +1,83 @@
|
|
|
1
|
+
import { LogLevel } from "./types-yQ6XOihF.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/console.ts
|
|
4
|
+
/**
|
|
5
|
+
* Numeric priority for log levels (higher = more severe)
|
|
6
|
+
*/
|
|
7
|
+
const LOG_LEVEL_PRIORITY = {
|
|
8
|
+
[LogLevel.Trace]: 10,
|
|
9
|
+
[LogLevel.Debug]: 20,
|
|
10
|
+
[LogLevel.Info]: 30,
|
|
11
|
+
[LogLevel.Warn]: 40,
|
|
12
|
+
[LogLevel.Error]: 50,
|
|
13
|
+
[LogLevel.Fatal]: 60,
|
|
14
|
+
[LogLevel.Silent]: 70
|
|
15
|
+
};
|
|
2
16
|
var ConsoleLogger = class ConsoleLogger {
|
|
17
|
+
level;
|
|
3
18
|
/**
|
|
4
19
|
* Creates a new ConsoleLogger instance.
|
|
5
20
|
*
|
|
6
21
|
* @param data - Initial context data to include in all log messages
|
|
22
|
+
* @param level - Minimum log level to output (default: Info)
|
|
7
23
|
*/
|
|
8
|
-
constructor(data = {}) {
|
|
24
|
+
constructor(data = {}, level = LogLevel.Info) {
|
|
9
25
|
this.data = data;
|
|
26
|
+
this.level = level;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a log level should be output based on the configured minimum level.
|
|
30
|
+
*/
|
|
31
|
+
shouldLog(level) {
|
|
32
|
+
if (this.level === LogLevel.Silent) return false;
|
|
33
|
+
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.level];
|
|
10
34
|
}
|
|
11
35
|
/**
|
|
12
36
|
* Creates a logging function that merges context data and adds timestamps.
|
|
13
37
|
*
|
|
14
38
|
* @param logMethod - The console method to use (e.g., console.log, console.error)
|
|
39
|
+
* @param level - The log level for this method
|
|
15
40
|
* @returns A LogFn that handles both structured and simple logging
|
|
16
41
|
* @private
|
|
17
42
|
*/
|
|
18
|
-
createLogFn(logMethod) {
|
|
19
|
-
return (
|
|
43
|
+
createLogFn(logMethod, level) {
|
|
44
|
+
return (objOrMsg, msg, ...args) => {
|
|
45
|
+
if (!this.shouldLog(level)) return;
|
|
20
46
|
const ts = Date.now();
|
|
21
|
-
|
|
47
|
+
if (typeof objOrMsg === "string") {
|
|
48
|
+
const logData$1 = {
|
|
49
|
+
...this.data,
|
|
50
|
+
msg: objOrMsg,
|
|
51
|
+
ts
|
|
52
|
+
};
|
|
53
|
+
logMethod(logData$1, ...args);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const logData = msg ? {
|
|
57
|
+
...this.data,
|
|
58
|
+
...objOrMsg,
|
|
59
|
+
msg,
|
|
60
|
+
ts
|
|
61
|
+
} : {
|
|
22
62
|
...this.data,
|
|
23
|
-
...
|
|
63
|
+
...objOrMsg,
|
|
24
64
|
ts
|
|
25
65
|
};
|
|
26
|
-
|
|
27
|
-
else logMethod(mergedData, ...args);
|
|
66
|
+
logMethod(logData, ...args);
|
|
28
67
|
};
|
|
29
68
|
}
|
|
69
|
+
/** Trace level logging function */
|
|
70
|
+
trace = this.createLogFn(console.trace.bind(console), LogLevel.Trace);
|
|
30
71
|
/** Debug level logging function */
|
|
31
|
-
debug = this.createLogFn(console.debug.bind(console));
|
|
72
|
+
debug = this.createLogFn(console.debug.bind(console), LogLevel.Debug);
|
|
32
73
|
/** Info level logging function */
|
|
33
|
-
info = this.createLogFn(console.info.bind(console));
|
|
74
|
+
info = this.createLogFn(console.info.bind(console), LogLevel.Info);
|
|
34
75
|
/** Warning level logging function */
|
|
35
|
-
warn = this.createLogFn(console.warn.bind(console));
|
|
76
|
+
warn = this.createLogFn(console.warn.bind(console), LogLevel.Warn);
|
|
36
77
|
/** Error level logging function */
|
|
37
|
-
error = this.createLogFn(console.error.bind(console));
|
|
78
|
+
error = this.createLogFn(console.error.bind(console), LogLevel.Error);
|
|
38
79
|
/** Fatal level logging function (uses console.error) */
|
|
39
|
-
fatal = this.createLogFn(console.error.bind(console));
|
|
40
|
-
/** Trace level logging function */
|
|
41
|
-
trace = this.createLogFn(console.trace.bind(console));
|
|
80
|
+
fatal = this.createLogFn(console.error.bind(console), LogLevel.Fatal);
|
|
42
81
|
/**
|
|
43
82
|
* Creates a child logger with additional context data.
|
|
44
83
|
* The child logger inherits all context from the parent and adds its own.
|
|
@@ -58,7 +97,7 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
58
97
|
return new ConsoleLogger({
|
|
59
98
|
...this.data,
|
|
60
99
|
...obj
|
|
61
|
-
});
|
|
100
|
+
}, this.level);
|
|
62
101
|
}
|
|
63
102
|
};
|
|
64
103
|
/**
|
|
@@ -66,14 +105,14 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
66
105
|
* ```typescript
|
|
67
106
|
* const logger = new ConsoleLogger({ app: 'myApp' });
|
|
68
107
|
* logger.info({ action: 'start' }, 'Application starting');
|
|
69
|
-
* // Logs: { app: 'myApp', action: 'start', ts: 1234567890 }
|
|
108
|
+
* // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
|
|
70
109
|
* ```
|
|
71
110
|
*
|
|
72
111
|
* @example Child logger usage
|
|
73
112
|
* ```typescript
|
|
74
113
|
* const childLogger = logger.child({ module: 'auth' });
|
|
75
114
|
* childLogger.debug({ userId: 123 }, 'User authenticated');
|
|
76
|
-
* // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 }
|
|
115
|
+
* // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
|
|
77
116
|
* ```
|
|
78
117
|
*
|
|
79
118
|
* @example Error logging with context
|
|
@@ -86,7 +125,26 @@ var ConsoleLogger = class ConsoleLogger {
|
|
|
86
125
|
* ```
|
|
87
126
|
*/
|
|
88
127
|
const DEFAULT_LOGGER = new ConsoleLogger();
|
|
128
|
+
/**
|
|
129
|
+
* Creates a console logger with the same API as pino's createLogger.
|
|
130
|
+
*
|
|
131
|
+
* @param options - Logger configuration options
|
|
132
|
+
* @returns A ConsoleLogger instance
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { createLogger } from '@geekmidas/logger/console';
|
|
137
|
+
* import { LogLevel } from '@geekmidas/logger';
|
|
138
|
+
*
|
|
139
|
+
* const logger = createLogger({ level: LogLevel.Debug });
|
|
140
|
+
* logger.debug('This will be logged');
|
|
141
|
+
* logger.trace('This will NOT be logged (below Debug level)');
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
function createLogger(options = {}) {
|
|
145
|
+
return new ConsoleLogger({}, options.level ?? LogLevel.Info);
|
|
146
|
+
}
|
|
89
147
|
|
|
90
148
|
//#endregion
|
|
91
|
-
export { ConsoleLogger, DEFAULT_LOGGER };
|
|
149
|
+
export { ConsoleLogger, DEFAULT_LOGGER, createLogger };
|
|
92
150
|
//# sourceMappingURL=console.mjs.map
|
package/dist/console.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.mjs","names":["data: object","logMethod: (...args: any[]) => void","
|
|
1
|
+
{"version":3,"file":"console.mjs","names":["LOG_LEVEL_PRIORITY: Record<LogLevel, number>","data: object","level: LogLevel","logMethod: (...args: any[]) => void","objOrMsg: T | string","msg?: string","logData","obj: object","options: CreateLoggerOptions"],"sources":["../src/console.ts"],"sourcesContent":["import type { CreateLoggerOptions, LogFn, Logger } from './types';\nimport { LogLevel } from './types';\n\n/**\n * Numeric priority for log levels (higher = more severe)\n */\nconst LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {\n [LogLevel.Trace]: 10,\n [LogLevel.Debug]: 20,\n [LogLevel.Info]: 30,\n [LogLevel.Warn]: 40,\n [LogLevel.Error]: 50,\n [LogLevel.Fatal]: 60,\n [LogLevel.Silent]: 70,\n};\n\nexport class ConsoleLogger implements Logger {\n private readonly level: LogLevel;\n\n /**\n * Creates a new ConsoleLogger instance.\n *\n * @param data - Initial context data to include in all log messages\n * @param level - Minimum log level to output (default: Info)\n */\n constructor(\n readonly data: object = {},\n level: LogLevel = LogLevel.Info,\n ) {\n this.level = level;\n }\n\n /**\n * Checks if a log level should be output based on the configured minimum level.\n */\n private shouldLog(level: LogLevel): boolean {\n if (this.level === LogLevel.Silent) {\n return false;\n }\n return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.level];\n }\n\n /**\n * Creates a logging function that merges context data and adds timestamps.\n *\n * @param logMethod - The console method to use (e.g., console.log, console.error)\n * @param level - The log level for this method\n * @returns A LogFn that handles both structured and simple logging\n * @private\n */\n private createLogFn(\n logMethod: (...args: any[]) => void,\n level: LogLevel,\n ): LogFn {\n return <T extends object>(\n objOrMsg: T | string,\n msg?: string,\n ...args: any[]\n ): void => {\n if (!this.shouldLog(level)) {\n return;\n }\n\n const ts = Date.now();\n\n // Handle simple string logging: logger.info('message')\n if (typeof objOrMsg === 'string') {\n const logData = { ...this.data, msg: objOrMsg, ts };\n logMethod(logData, ...args);\n return;\n }\n\n // Handle structured logging: logger.info({ data }, 'message')\n const logData = msg\n ? { ...this.data, ...objOrMsg, msg, ts }\n : { ...this.data, ...objOrMsg, ts };\n logMethod(logData, ...args);\n };\n }\n\n /** Trace level logging function */\n trace: LogFn = this.createLogFn(console.trace.bind(console), LogLevel.Trace);\n /** Debug level logging function */\n debug: LogFn = this.createLogFn(console.debug.bind(console), LogLevel.Debug);\n /** Info level logging function */\n info: LogFn = this.createLogFn(console.info.bind(console), LogLevel.Info);\n /** Warning level logging function */\n warn: LogFn = this.createLogFn(console.warn.bind(console), LogLevel.Warn);\n /** Error level logging function */\n error: LogFn = this.createLogFn(console.error.bind(console), LogLevel.Error);\n /** Fatal level logging function (uses console.error) */\n fatal: LogFn = this.createLogFn(console.error.bind(console), LogLevel.Fatal);\n\n /**\n * Creates a child logger with additional context data.\n * The child logger inherits all context from the parent and adds its own.\n *\n * @param obj - Additional context data for the child logger\n * @returns A new ConsoleLogger instance with merged context\n *\n * @example\n * ```typescript\n * const parentLogger = new ConsoleLogger({ app: 'myApp' });\n * const childLogger = parentLogger.child({ module: 'database' });\n * childLogger.info({ query: 'SELECT * FROM users' }, 'Query executed');\n * // Context includes both { app: 'myApp' } and { module: 'database' }\n * ```\n */\n child(obj: object): Logger {\n return new ConsoleLogger(\n {\n ...this.data,\n ...obj,\n },\n this.level,\n );\n }\n}\n\n/**\n * @example Basic usage\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp' });\n * logger.info({ action: 'start' }, 'Application starting');\n * // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }\n * ```\n *\n * @example Child logger usage\n * ```typescript\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ userId: 123 }, 'User authenticated');\n * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }\n * ```\n *\n * @example Error logging with context\n * ```typescript\n * try {\n * await someOperation();\n * } catch (error) {\n * logger.error({ error, operation: 'someOperation' }, 'Operation failed');\n * }\n * ```\n */\n\nexport const DEFAULT_LOGGER = new ConsoleLogger() as any;\n\n/**\n * Creates a console logger with the same API as pino's createLogger.\n *\n * @param options - Logger configuration options\n * @returns A ConsoleLogger instance\n *\n * @example\n * ```typescript\n * import { createLogger } from '@geekmidas/logger/console';\n * import { LogLevel } from '@geekmidas/logger';\n *\n * const logger = createLogger({ level: LogLevel.Debug });\n * logger.debug('This will be logged');\n * logger.trace('This will NOT be logged (below Debug level)');\n * ```\n */\nexport function createLogger(options: CreateLoggerOptions = {}): Logger {\n return new ConsoleLogger({}, options.level ?? LogLevel.Info);\n}\n"],"mappings":";;;;;;AAMA,MAAMA,qBAA+C;EAClD,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB,SAAS,SAAS;AACpB;AAED,IAAa,gBAAb,MAAa,cAAgC;CAC3C,AAAiB;;;;;;;CAQjB,YACWC,OAAe,CAAE,GAC1BC,QAAkB,SAAS,MAC3B;EAFS;AAGT,OAAK,QAAQ;CACd;;;;CAKD,AAAQ,UAAUA,OAA0B;AAC1C,MAAI,KAAK,UAAU,SAAS,OAC1B,QAAO;AAET,SAAO,mBAAmB,UAAU,mBAAmB,KAAK;CAC7D;;;;;;;;;CAUD,AAAQ,YACNC,WACAD,OACO;AACP,SAAO,CACLE,UACAC,KACA,GAAG,SACM;AACT,QAAK,KAAK,UAAU,MAAM,CACxB;GAGF,MAAM,KAAK,KAAK,KAAK;AAGrB,cAAW,aAAa,UAAU;IAChC,MAAMC,YAAU;KAAE,GAAG,KAAK;KAAM,KAAK;KAAU;IAAI;AACnD,cAAUA,WAAS,GAAG,KAAK;AAC3B;GACD;GAGD,MAAM,UAAU,MACZ;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;IAAK;GAAI,IACtC;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;GAAI;AACrC,aAAU,SAAS,GAAG,KAAK;EAC5B;CACF;;CAGD,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,MAAM;;CAE5E,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,MAAM;;CAE5E,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,EAAE,SAAS,KAAK;;CAEzE,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,EAAE,SAAS,KAAK;;CAEzE,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,MAAM;;CAE5E,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,MAAM;;;;;;;;;;;;;;;;CAiB5E,MAAMC,KAAqB;AACzB,SAAO,IAAI,cACT;GACE,GAAG,KAAK;GACR,GAAG;EACJ,GACD,KAAK;CAER;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA2BD,MAAa,iBAAiB,IAAI;;;;;;;;;;;;;;;;;AAkBlC,SAAgB,aAAaC,UAA+B,CAAE,GAAU;AACtE,QAAO,IAAI,cAAc,CAAE,GAAE,QAAQ,SAAS,SAAS;AACxD"}
|