@geekmidas/logger 0.0.1 → 0.1.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/dist/pino.mjs CHANGED
@@ -1,14 +1,115 @@
1
1
  import { pino } from "pino";
2
2
 
3
3
  //#region src/pino.ts
4
- function createLogger(options) {
4
+ /**
5
+ * Default sensitive field paths for redaction.
6
+ *
7
+ * These paths are automatically used when `redact: true` is set,
8
+ * and merged with custom paths unless `resolution: 'override'` is specified.
9
+ *
10
+ * Includes:
11
+ * - Authentication: password, token, apiKey, authorization, credentials
12
+ * - Headers: authorization, cookie, x-api-key, x-auth-token
13
+ * - Personal data: ssn, creditCard, cvv, pin
14
+ * - Secrets: secret, connectionString, databaseUrl
15
+ * - Wildcards: *.password, *.secret, *.token (catches nested fields)
16
+ */
17
+ const DEFAULT_REDACT_PATHS = [
18
+ "password",
19
+ "pass",
20
+ "passwd",
21
+ "secret",
22
+ "token",
23
+ "accessToken",
24
+ "refreshToken",
25
+ "idToken",
26
+ "apiKey",
27
+ "api_key",
28
+ "apikey",
29
+ "auth",
30
+ "authorization",
31
+ "credential",
32
+ "credentials",
33
+ "*.password",
34
+ "*.secret",
35
+ "*.token",
36
+ "*.apiKey",
37
+ "*.api_key",
38
+ "*.authorization",
39
+ "*.accessToken",
40
+ "*.refreshToken",
41
+ "headers.authorization",
42
+ "headers.Authorization",
43
+ "headers[\"authorization\"]",
44
+ "headers[\"Authorization\"]",
45
+ "headers.cookie",
46
+ "headers.Cookie",
47
+ "headers[\"x-api-key\"]",
48
+ "headers[\"X-Api-Key\"]",
49
+ "headers[\"x-auth-token\"]",
50
+ "headers[\"X-Auth-Token\"]",
51
+ "ssn",
52
+ "socialSecurityNumber",
53
+ "social_security_number",
54
+ "creditCard",
55
+ "credit_card",
56
+ "cardNumber",
57
+ "card_number",
58
+ "cvv",
59
+ "cvc",
60
+ "pin",
61
+ "connectionString",
62
+ "connection_string",
63
+ "databaseUrl",
64
+ "database_url"
65
+ ];
66
+ /**
67
+ * Resolves redaction configuration from options.
68
+ * Returns undefined if redaction is disabled, or a pino-compatible redact config.
69
+ *
70
+ * By default (resolution: 'merge'), custom paths are merged with DEFAULT_REDACT_PATHS.
71
+ * With resolution: 'override', only the custom paths are used.
72
+ */
73
+ function resolveRedactConfig(redact) {
74
+ if (redact === void 0 || redact === false) return void 0;
75
+ if (redact === true) return DEFAULT_REDACT_PATHS;
76
+ if (Array.isArray(redact)) return [...DEFAULT_REDACT_PATHS, ...redact];
77
+ const { resolution = "merge", paths, censor, remove } = redact;
78
+ const resolvedPaths = resolution === "override" ? paths : [...DEFAULT_REDACT_PATHS, ...paths];
79
+ const config = { paths: resolvedPaths };
80
+ if (censor !== void 0) config.censor = censor;
81
+ if (remove !== void 0) config.remove = remove;
82
+ return config;
83
+ }
84
+ /**
85
+ * Creates a pino logger instance with optional redaction support.
86
+ *
87
+ * @param options - Logger configuration options
88
+ * @returns A configured pino logger instance
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Basic logger
93
+ * const logger = createLogger({ level: 'debug' });
94
+ *
95
+ * // With redaction enabled
96
+ * const secureLogger = createLogger({ redact: true });
97
+ *
98
+ * // Pretty printing in development
99
+ * const devLogger = createLogger({ pretty: true, redact: true });
100
+ * ```
101
+ */
102
+ function createLogger(options = {}) {
5
103
  const pretty = options?.pretty && process.NODE_ENV !== "production";
6
104
  const baseOptions = pretty ? { transport: {
7
105
  target: "pino-pretty",
8
106
  options: { colorize: true }
9
107
  } } : {};
108
+ const redact = resolveRedactConfig(options.redact);
10
109
  return pino({
11
110
  ...baseOptions,
111
+ ...options.level && { level: options.level },
112
+ ...redact && { redact },
12
113
  formatters: {
13
114
  bindings() {
14
115
  return { nodeVersion: process.version };
@@ -21,5 +122,5 @@ function createLogger(options) {
21
122
  }
22
123
 
23
124
  //#endregion
24
- export { createLogger };
125
+ export { DEFAULT_REDACT_PATHS, createLogger };
25
126
  //# sourceMappingURL=pino.mjs.map
package/dist/pino.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pino.mjs","names":["options: CreateLoggerOptions"],"sources":["../src/pino.ts"],"sourcesContent":["import { pino } from 'pino';\nimport type { CreateLoggerOptions } from './types';\n\nexport function createLogger(options: CreateLoggerOptions) {\n // @ts-ignore\n const pretty = options?.pretty && process.NODE_ENV !== 'production';\n const baseOptions = pretty\n ? {\n transport: {\n target: 'pino-pretty',\n options: { colorize: true },\n },\n }\n : {};\n return pino({\n ...baseOptions,\n formatters: {\n bindings() {\n return { nodeVersion: process.version };\n },\n level: (label) => {\n return { level: label.toUpperCase() };\n },\n },\n });\n}\n"],"mappings":";;;AAGA,SAAgB,aAAaA,SAA8B;CAEzD,MAAM,SAAS,SAAS,UAAU,QAAQ,aAAa;CACvD,MAAM,cAAc,SAChB,EACE,WAAW;EACT,QAAQ;EACR,SAAS,EAAE,UAAU,KAAM;CAC5B,EACF,IACD,CAAE;AACN,QAAO,KAAK;EACV,GAAG;EACH,YAAY;GACV,WAAW;AACT,WAAO,EAAE,aAAa,QAAQ,QAAS;GACxC;GACD,OAAO,CAAC,UAAU;AAChB,WAAO,EAAE,OAAO,MAAM,aAAa,CAAE;GACtC;EACF;CACF,EAAC;AACH"}
1
+ {"version":3,"file":"pino.mjs","names":["DEFAULT_REDACT_PATHS: string[]","redact: boolean | RedactOptions | undefined","config: PinoRedactConfig","options: CreateLoggerOptions"],"sources":["../src/pino.ts"],"sourcesContent":["/**\n * Pino logger with built-in redaction support for sensitive data.\n *\n * @example\n * ```typescript\n * import { createLogger, DEFAULT_REDACT_PATHS } from '@geekmidas/logger/pino';\n *\n * // Enable redaction with sensible defaults\n * const logger = createLogger({ redact: true });\n *\n * // Sensitive data is automatically masked\n * logger.info({ password: 'secret123', user: 'john' }, 'Login');\n * // Output: { password: '[Redacted]', user: 'john' } Login\n *\n * // Add custom paths (merged with defaults)\n * const logger2 = createLogger({ redact: ['user.ssn'] });\n *\n * // Override defaults for full control\n * const logger3 = createLogger({\n * redact: {\n * paths: ['onlyThis'],\n * resolution: 'override',\n * }\n * });\n * ```\n *\n * @module\n */\nimport { pino } from 'pino';\nimport type { CreateLoggerOptions, RedactOptions } from './types';\n\n/**\n * Default sensitive field paths for redaction.\n *\n * These paths are automatically used when `redact: true` is set,\n * and merged with custom paths unless `resolution: 'override'` is specified.\n *\n * Includes:\n * - Authentication: password, token, apiKey, authorization, credentials\n * - Headers: authorization, cookie, x-api-key, x-auth-token\n * - Personal data: ssn, creditCard, cvv, pin\n * - Secrets: secret, connectionString, databaseUrl\n * - Wildcards: *.password, *.secret, *.token (catches nested fields)\n */\nexport const DEFAULT_REDACT_PATHS: string[] = [\n // Authentication & authorization\n 'password',\n 'pass',\n 'passwd',\n 'secret',\n 'token',\n 'accessToken',\n 'refreshToken',\n 'idToken',\n 'apiKey',\n 'api_key',\n 'apikey',\n 'auth',\n 'authorization',\n 'credential',\n 'credentials',\n\n // Common nested patterns (headers, body, etc.)\n '*.password',\n '*.secret',\n '*.token',\n '*.apiKey',\n '*.api_key',\n '*.authorization',\n '*.accessToken',\n '*.refreshToken',\n\n // HTTP headers (case variations)\n 'headers.authorization',\n 'headers.Authorization',\n 'headers[\"authorization\"]',\n 'headers[\"Authorization\"]',\n 'headers.cookie',\n 'headers.Cookie',\n 'headers[\"x-api-key\"]',\n 'headers[\"X-Api-Key\"]',\n 'headers[\"x-auth-token\"]',\n 'headers[\"X-Auth-Token\"]',\n\n // Common sensitive data fields\n 'ssn',\n 'socialSecurityNumber',\n 'social_security_number',\n 'creditCard',\n 'credit_card',\n 'cardNumber',\n 'card_number',\n 'cvv',\n 'cvc',\n 'pin',\n\n // Database & connection strings\n 'connectionString',\n 'connection_string',\n 'databaseUrl',\n 'database_url',\n];\n\n/**\n * Type for the resolved pino redact config (without our custom resolution field).\n */\ntype PinoRedactConfig =\n | string[]\n | {\n paths: string[];\n censor?: string | ((value: unknown, path: string[]) => unknown);\n remove?: boolean;\n };\n\n/**\n * Resolves redaction configuration from options.\n * Returns undefined if redaction is disabled, or a pino-compatible redact config.\n *\n * By default (resolution: 'merge'), custom paths are merged with DEFAULT_REDACT_PATHS.\n * With resolution: 'override', only the custom paths are used.\n */\nfunction resolveRedactConfig(\n redact: boolean | RedactOptions | undefined,\n): PinoRedactConfig | undefined {\n if (redact === undefined || redact === false) {\n return undefined;\n }\n\n if (redact === true) {\n return DEFAULT_REDACT_PATHS;\n }\n\n // Array syntax - merge with defaults\n if (Array.isArray(redact)) {\n return [...DEFAULT_REDACT_PATHS, ...redact];\n }\n\n // Object syntax - check resolution mode\n const { resolution = 'merge', paths, censor, remove } = redact;\n\n const resolvedPaths =\n resolution === 'override' ? paths : [...DEFAULT_REDACT_PATHS, ...paths];\n\n // Return clean pino config without our resolution field\n const config: PinoRedactConfig = { paths: resolvedPaths };\n if (censor !== undefined) config.censor = censor;\n if (remove !== undefined) config.remove = remove;\n\n return config;\n}\n\n/**\n * Creates a pino logger instance with optional redaction support.\n *\n * @param options - Logger configuration options\n * @returns A configured pino logger instance\n *\n * @example\n * ```typescript\n * // Basic logger\n * const logger = createLogger({ level: 'debug' });\n *\n * // With redaction enabled\n * const secureLogger = createLogger({ redact: true });\n *\n * // Pretty printing in development\n * const devLogger = createLogger({ pretty: true, redact: true });\n * ```\n */\nexport function createLogger(options: CreateLoggerOptions = {}) {\n // @ts-ignore\n const pretty = options?.pretty && process.NODE_ENV !== 'production';\n const baseOptions = pretty\n ? {\n transport: {\n target: 'pino-pretty',\n options: { colorize: true },\n },\n }\n : {};\n\n const redact = resolveRedactConfig(options.redact);\n\n return pino({\n ...baseOptions,\n ...(options.level && { level: options.level }),\n ...(redact && { redact }),\n formatters: {\n bindings() {\n return { nodeVersion: process.version };\n },\n level: (label) => {\n return { level: label.toUpperCase() };\n },\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4CA,MAAaA,uBAAiC;CAE5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;AACD;;;;;;;;AAoBD,SAAS,oBACPC,QAC8B;AAC9B,KAAI,qBAAwB,WAAW,MACrC;AAGF,KAAI,WAAW,KACb,QAAO;AAIT,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,CAAC,GAAG,sBAAsB,GAAG,MAAO;CAI7C,MAAM,EAAE,aAAa,SAAS,OAAO,QAAQ,QAAQ,GAAG;CAExD,MAAM,gBACJ,eAAe,aAAa,QAAQ,CAAC,GAAG,sBAAsB,GAAG,KAAM;CAGzE,MAAMC,SAA2B,EAAE,OAAO,cAAe;AACzD,KAAI,kBAAsB,QAAO,SAAS;AAC1C,KAAI,kBAAsB,QAAO,SAAS;AAE1C,QAAO;AACR;;;;;;;;;;;;;;;;;;;AAoBD,SAAgB,aAAaC,UAA+B,CAAE,GAAE;CAE9D,MAAM,SAAS,SAAS,UAAU,QAAQ,aAAa;CACvD,MAAM,cAAc,SAChB,EACE,WAAW;EACT,QAAQ;EACR,SAAS,EAAE,UAAU,KAAM;CAC5B,EACF,IACD,CAAE;CAEN,MAAM,SAAS,oBAAoB,QAAQ,OAAO;AAElD,QAAO,KAAK;EACV,GAAG;EACH,GAAI,QAAQ,SAAS,EAAE,OAAO,QAAQ,MAAO;EAC7C,GAAI,UAAU,EAAE,OAAQ;EACxB,YAAY;GACV,WAAW;AACT,WAAO,EAAE,aAAa,QAAQ,QAAS;GACxC;GACD,OAAO,CAAC,UAAU;AAChB,WAAO,EAAE,OAAO,MAAM,aAAa,CAAE;GACtC;EACF;CACF,EAAC;AACH"}
@@ -72,10 +72,94 @@ declare enum LogLevel {
72
72
  Fatal = "fatal",
73
73
  Silent = "silent",
74
74
  }
75
+ /**
76
+ * Redaction configuration for masking sensitive data in logs.
77
+ * Uses pino's fast-redact library under the hood.
78
+ *
79
+ * By default, custom paths are merged with the default sensitive paths.
80
+ * Use `resolution: 'override'` to use only your custom paths.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // Simple path array (merges with defaults)
85
+ * redact: ['user.ssn', 'custom.field']
86
+ *
87
+ * // Override defaults completely
88
+ * redact: {
89
+ * paths: ['only.these.paths'],
90
+ * resolution: 'override',
91
+ * }
92
+ *
93
+ * // With custom censor
94
+ * redact: {
95
+ * paths: ['extra.secret'],
96
+ * censor: '***',
97
+ * }
98
+ *
99
+ * // Remove fields entirely
100
+ * redact: {
101
+ * paths: ['temporary.data'],
102
+ * remove: true,
103
+ * }
104
+ * ```
105
+ */
106
+ type RedactOptions = string[] | {
107
+ /** Paths to redact using dot notation or bracket notation for special chars */
108
+ paths: string[];
109
+ /** Custom replacement text (default: '[REDACTED]') */
110
+ censor?: string | ((value: unknown, path: string[]) => unknown);
111
+ /** Remove the field entirely instead of replacing (default: false) */
112
+ remove?: boolean;
113
+ /**
114
+ * How to combine custom paths with default sensitive paths.
115
+ * - 'merge': Custom paths are added to default paths (default)
116
+ * - 'override': Only custom paths are used, defaults are ignored
117
+ */
118
+ resolution?: 'merge' | 'override';
119
+ };
75
120
  type CreateLoggerOptions = {
121
+ /** Enable pretty printing with colors (disabled in production) */
76
122
  pretty?: boolean;
123
+ /** Minimum log level to output */
77
124
  level?: LogLevel;
125
+ /**
126
+ * Redaction configuration for masking sensitive data.
127
+ *
128
+ * - `true`: Uses default sensitive paths (password, token, secret, etc.)
129
+ * - `false` or `undefined`: No redaction applied
130
+ * - `string[]`: Custom paths merged with defaults
131
+ * - `object`: Advanced config with paths, censor, remove, and resolution options
132
+ *
133
+ * By default, custom paths are **merged** with the default sensitive paths.
134
+ * Use `resolution: 'override'` to disable defaults and use only your paths.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Use defaults only
139
+ * createLogger({ redact: true });
140
+ *
141
+ * // Add custom paths (merged with defaults)
142
+ * createLogger({ redact: ['user.ssn', 'custom.field'] });
143
+ *
144
+ * // Override defaults completely
145
+ * createLogger({
146
+ * redact: {
147
+ * paths: ['only.these.paths'],
148
+ * resolution: 'override',
149
+ * }
150
+ * });
151
+ *
152
+ * // Merge with custom censor
153
+ * createLogger({
154
+ * redact: {
155
+ * paths: ['extra.secret'],
156
+ * censor: '***',
157
+ * }
158
+ * });
159
+ * ```
160
+ */
161
+ redact?: boolean | RedactOptions;
78
162
  };
79
163
  //#endregion
80
- export { CreateLoggerOptions, LogFn, LogLevel, Logger };
81
- //# sourceMappingURL=types-C1RfRbo6.d.mts.map
164
+ export { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions };
165
+ //# sourceMappingURL=types-BFiJzL9N.d.mts.map
@@ -72,10 +72,94 @@ declare enum LogLevel {
72
72
  Fatal = "fatal",
73
73
  Silent = "silent",
74
74
  }
75
+ /**
76
+ * Redaction configuration for masking sensitive data in logs.
77
+ * Uses pino's fast-redact library under the hood.
78
+ *
79
+ * By default, custom paths are merged with the default sensitive paths.
80
+ * Use `resolution: 'override'` to use only your custom paths.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // Simple path array (merges with defaults)
85
+ * redact: ['user.ssn', 'custom.field']
86
+ *
87
+ * // Override defaults completely
88
+ * redact: {
89
+ * paths: ['only.these.paths'],
90
+ * resolution: 'override',
91
+ * }
92
+ *
93
+ * // With custom censor
94
+ * redact: {
95
+ * paths: ['extra.secret'],
96
+ * censor: '***',
97
+ * }
98
+ *
99
+ * // Remove fields entirely
100
+ * redact: {
101
+ * paths: ['temporary.data'],
102
+ * remove: true,
103
+ * }
104
+ * ```
105
+ */
106
+ type RedactOptions = string[] | {
107
+ /** Paths to redact using dot notation or bracket notation for special chars */
108
+ paths: string[];
109
+ /** Custom replacement text (default: '[REDACTED]') */
110
+ censor?: string | ((value: unknown, path: string[]) => unknown);
111
+ /** Remove the field entirely instead of replacing (default: false) */
112
+ remove?: boolean;
113
+ /**
114
+ * How to combine custom paths with default sensitive paths.
115
+ * - 'merge': Custom paths are added to default paths (default)
116
+ * - 'override': Only custom paths are used, defaults are ignored
117
+ */
118
+ resolution?: 'merge' | 'override';
119
+ };
75
120
  type CreateLoggerOptions = {
121
+ /** Enable pretty printing with colors (disabled in production) */
76
122
  pretty?: boolean;
123
+ /** Minimum log level to output */
77
124
  level?: LogLevel;
125
+ /**
126
+ * Redaction configuration for masking sensitive data.
127
+ *
128
+ * - `true`: Uses default sensitive paths (password, token, secret, etc.)
129
+ * - `false` or `undefined`: No redaction applied
130
+ * - `string[]`: Custom paths merged with defaults
131
+ * - `object`: Advanced config with paths, censor, remove, and resolution options
132
+ *
133
+ * By default, custom paths are **merged** with the default sensitive paths.
134
+ * Use `resolution: 'override'` to disable defaults and use only your paths.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * // Use defaults only
139
+ * createLogger({ redact: true });
140
+ *
141
+ * // Add custom paths (merged with defaults)
142
+ * createLogger({ redact: ['user.ssn', 'custom.field'] });
143
+ *
144
+ * // Override defaults completely
145
+ * createLogger({
146
+ * redact: {
147
+ * paths: ['only.these.paths'],
148
+ * resolution: 'override',
149
+ * }
150
+ * });
151
+ *
152
+ * // Merge with custom censor
153
+ * createLogger({
154
+ * redact: {
155
+ * paths: ['extra.secret'],
156
+ * censor: '***',
157
+ * }
158
+ * });
159
+ * ```
160
+ */
161
+ redact?: boolean | RedactOptions;
78
162
  };
79
163
  //#endregion
80
- export { CreateLoggerOptions, LogFn, LogLevel, Logger };
81
- //# sourceMappingURL=types-DXdmn7h5.d.cts.map
164
+ export { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions };
165
+ //# sourceMappingURL=types-JxCFymH0.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types-ag_0Cvbg.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Logging function type that supports both structured and simple logging.\n * Can be called with an object for structured logging or just a message string.\n *\n * @example\n * ```typescript\n * // Structured logging with context object\n * logger.info({ userId: 123, action: 'login' }, 'User logged in');\n *\n * // Simple string logging\n * logger.info('Application started');\n * ```\n */\nexport type LogFn = {\n /** Structured logging with context object, optional message, and additional arguments */\n <T extends object>(obj: T, msg?: string, ...args: any[]): void;\n /** Simple string logging */\n (msg: string): void;\n};\n\n/**\n * Standard logger interface with multiple log levels and child logger support.\n * Follows common logging patterns with structured logging capabilities.\n *\n * @interface Logger\n */\nexport interface Logger {\n /** Debug level logging - verbose information for debugging */\n debug: LogFn;\n /** Info level logging - general informational messages */\n info: LogFn;\n /** Warning level logging - potentially harmful situations */\n warn: LogFn;\n /** Error level logging - error events that might still allow the application to continue */\n error: LogFn;\n /** Fatal level logging - severe errors that will likely cause the application to abort */\n fatal: LogFn;\n /** Trace level logging - most detailed information */\n trace: LogFn;\n /**\n * Creates a child logger with additional context.\n * Child loggers inherit parent context and add their own.\n *\n * @param obj - Additional context to include in all child logger calls\n * @returns A new Logger instance with merged context\n */\n child: (obj: object) => Logger;\n}\n\n/**\n * Console-based logger implementation that outputs to standard console methods.\n * Supports structured logging with automatic timestamp injection and context inheritance.\n *\n * @implements {Logger}\n *\n * @example\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });\n * logger.info({ userId: 123 }, 'User action performed');\n * // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed\n *\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ action: 'validate' }, 'Validating token');\n * // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token\n * ```\n */\nexport enum LogLevel {\n Trace = 'trace',\n Debug = 'debug',\n Info = 'info',\n Warn = 'warn',\n Error = 'error',\n Fatal = 'fatal',\n Silent = 'silent',\n}\n\nexport type CreateLoggerOptions = {\n pretty?: boolean;\n level?: LogLevel;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkEA,IAAY,gDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
1
+ {"version":3,"file":"types-ag_0Cvbg.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Logging function type that supports both structured and simple logging.\n * Can be called with an object for structured logging or just a message string.\n *\n * @example\n * ```typescript\n * // Structured logging with context object\n * logger.info({ userId: 123, action: 'login' }, 'User logged in');\n *\n * // Simple string logging\n * logger.info('Application started');\n * ```\n */\nexport type LogFn = {\n /** Structured logging with context object, optional message, and additional arguments */\n <T extends object>(obj: T, msg?: string, ...args: any[]): void;\n /** Simple string logging */\n (msg: string): void;\n};\n\n/**\n * Standard logger interface with multiple log levels and child logger support.\n * Follows common logging patterns with structured logging capabilities.\n *\n * @interface Logger\n */\nexport interface Logger {\n /** Debug level logging - verbose information for debugging */\n debug: LogFn;\n /** Info level logging - general informational messages */\n info: LogFn;\n /** Warning level logging - potentially harmful situations */\n warn: LogFn;\n /** Error level logging - error events that might still allow the application to continue */\n error: LogFn;\n /** Fatal level logging - severe errors that will likely cause the application to abort */\n fatal: LogFn;\n /** Trace level logging - most detailed information */\n trace: LogFn;\n /**\n * Creates a child logger with additional context.\n * Child loggers inherit parent context and add their own.\n *\n * @param obj - Additional context to include in all child logger calls\n * @returns A new Logger instance with merged context\n */\n child: (obj: object) => Logger;\n}\n\n/**\n * Console-based logger implementation that outputs to standard console methods.\n * Supports structured logging with automatic timestamp injection and context inheritance.\n *\n * @implements {Logger}\n *\n * @example\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });\n * logger.info({ userId: 123 }, 'User action performed');\n * // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed\n *\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ action: 'validate' }, 'Validating token');\n * // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token\n * ```\n */\nexport enum LogLevel {\n Trace = 'trace',\n Debug = 'debug',\n Info = 'info',\n Warn = 'warn',\n Error = 'error',\n Fatal = 'fatal',\n Silent = 'silent',\n}\n\n/**\n * Redaction configuration for masking sensitive data in logs.\n * Uses pino's fast-redact library under the hood.\n *\n * By default, custom paths are merged with the default sensitive paths.\n * Use `resolution: 'override'` to use only your custom paths.\n *\n * @example\n * ```typescript\n * // Simple path array (merges with defaults)\n * redact: ['user.ssn', 'custom.field']\n *\n * // Override defaults completely\n * redact: {\n * paths: ['only.these.paths'],\n * resolution: 'override',\n * }\n *\n * // With custom censor\n * redact: {\n * paths: ['extra.secret'],\n * censor: '***',\n * }\n *\n * // Remove fields entirely\n * redact: {\n * paths: ['temporary.data'],\n * remove: true,\n * }\n * ```\n */\nexport type RedactOptions =\n | string[]\n | {\n /** Paths to redact using dot notation or bracket notation for special chars */\n paths: string[];\n /** Custom replacement text (default: '[REDACTED]') */\n censor?: string | ((value: unknown, path: string[]) => unknown);\n /** Remove the field entirely instead of replacing (default: false) */\n remove?: boolean;\n /**\n * How to combine custom paths with default sensitive paths.\n * - 'merge': Custom paths are added to default paths (default)\n * - 'override': Only custom paths are used, defaults are ignored\n */\n resolution?: 'merge' | 'override';\n };\n\nexport type CreateLoggerOptions = {\n /** Enable pretty printing with colors (disabled in production) */\n pretty?: boolean;\n /** Minimum log level to output */\n level?: LogLevel;\n /**\n * Redaction configuration for masking sensitive data.\n *\n * - `true`: Uses default sensitive paths (password, token, secret, etc.)\n * - `false` or `undefined`: No redaction applied\n * - `string[]`: Custom paths merged with defaults\n * - `object`: Advanced config with paths, censor, remove, and resolution options\n *\n * By default, custom paths are **merged** with the default sensitive paths.\n * Use `resolution: 'override'` to disable defaults and use only your paths.\n *\n * @example\n * ```typescript\n * // Use defaults only\n * createLogger({ redact: true });\n *\n * // Add custom paths (merged with defaults)\n * createLogger({ redact: ['user.ssn', 'custom.field'] });\n *\n * // Override defaults completely\n * createLogger({\n * redact: {\n * paths: ['only.these.paths'],\n * resolution: 'override',\n * }\n * });\n *\n * // Merge with custom censor\n * createLogger({\n * redact: {\n * paths: ['extra.secret'],\n * censor: '***',\n * }\n * });\n * ```\n */\n redact?: boolean | RedactOptions;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkEA,IAAY,gDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"types-yQ6XOihF.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Logging function type that supports both structured and simple logging.\n * Can be called with an object for structured logging or just a message string.\n *\n * @example\n * ```typescript\n * // Structured logging with context object\n * logger.info({ userId: 123, action: 'login' }, 'User logged in');\n *\n * // Simple string logging\n * logger.info('Application started');\n * ```\n */\nexport type LogFn = {\n /** Structured logging with context object, optional message, and additional arguments */\n <T extends object>(obj: T, msg?: string, ...args: any[]): void;\n /** Simple string logging */\n (msg: string): void;\n};\n\n/**\n * Standard logger interface with multiple log levels and child logger support.\n * Follows common logging patterns with structured logging capabilities.\n *\n * @interface Logger\n */\nexport interface Logger {\n /** Debug level logging - verbose information for debugging */\n debug: LogFn;\n /** Info level logging - general informational messages */\n info: LogFn;\n /** Warning level logging - potentially harmful situations */\n warn: LogFn;\n /** Error level logging - error events that might still allow the application to continue */\n error: LogFn;\n /** Fatal level logging - severe errors that will likely cause the application to abort */\n fatal: LogFn;\n /** Trace level logging - most detailed information */\n trace: LogFn;\n /**\n * Creates a child logger with additional context.\n * Child loggers inherit parent context and add their own.\n *\n * @param obj - Additional context to include in all child logger calls\n * @returns A new Logger instance with merged context\n */\n child: (obj: object) => Logger;\n}\n\n/**\n * Console-based logger implementation that outputs to standard console methods.\n * Supports structured logging with automatic timestamp injection and context inheritance.\n *\n * @implements {Logger}\n *\n * @example\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });\n * logger.info({ userId: 123 }, 'User action performed');\n * // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed\n *\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ action: 'validate' }, 'Validating token');\n * // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token\n * ```\n */\nexport enum LogLevel {\n Trace = 'trace',\n Debug = 'debug',\n Info = 'info',\n Warn = 'warn',\n Error = 'error',\n Fatal = 'fatal',\n Silent = 'silent',\n}\n\nexport type CreateLoggerOptions = {\n pretty?: boolean;\n level?: LogLevel;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkEA,IAAY,gDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
1
+ {"version":3,"file":"types-yQ6XOihF.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Logging function type that supports both structured and simple logging.\n * Can be called with an object for structured logging or just a message string.\n *\n * @example\n * ```typescript\n * // Structured logging with context object\n * logger.info({ userId: 123, action: 'login' }, 'User logged in');\n *\n * // Simple string logging\n * logger.info('Application started');\n * ```\n */\nexport type LogFn = {\n /** Structured logging with context object, optional message, and additional arguments */\n <T extends object>(obj: T, msg?: string, ...args: any[]): void;\n /** Simple string logging */\n (msg: string): void;\n};\n\n/**\n * Standard logger interface with multiple log levels and child logger support.\n * Follows common logging patterns with structured logging capabilities.\n *\n * @interface Logger\n */\nexport interface Logger {\n /** Debug level logging - verbose information for debugging */\n debug: LogFn;\n /** Info level logging - general informational messages */\n info: LogFn;\n /** Warning level logging - potentially harmful situations */\n warn: LogFn;\n /** Error level logging - error events that might still allow the application to continue */\n error: LogFn;\n /** Fatal level logging - severe errors that will likely cause the application to abort */\n fatal: LogFn;\n /** Trace level logging - most detailed information */\n trace: LogFn;\n /**\n * Creates a child logger with additional context.\n * Child loggers inherit parent context and add their own.\n *\n * @param obj - Additional context to include in all child logger calls\n * @returns A new Logger instance with merged context\n */\n child: (obj: object) => Logger;\n}\n\n/**\n * Console-based logger implementation that outputs to standard console methods.\n * Supports structured logging with automatic timestamp injection and context inheritance.\n *\n * @implements {Logger}\n *\n * @example\n * ```typescript\n * const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });\n * logger.info({ userId: 123 }, 'User action performed');\n * // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed\n *\n * const childLogger = logger.child({ module: 'auth' });\n * childLogger.debug({ action: 'validate' }, 'Validating token');\n * // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token\n * ```\n */\nexport enum LogLevel {\n Trace = 'trace',\n Debug = 'debug',\n Info = 'info',\n Warn = 'warn',\n Error = 'error',\n Fatal = 'fatal',\n Silent = 'silent',\n}\n\n/**\n * Redaction configuration for masking sensitive data in logs.\n * Uses pino's fast-redact library under the hood.\n *\n * By default, custom paths are merged with the default sensitive paths.\n * Use `resolution: 'override'` to use only your custom paths.\n *\n * @example\n * ```typescript\n * // Simple path array (merges with defaults)\n * redact: ['user.ssn', 'custom.field']\n *\n * // Override defaults completely\n * redact: {\n * paths: ['only.these.paths'],\n * resolution: 'override',\n * }\n *\n * // With custom censor\n * redact: {\n * paths: ['extra.secret'],\n * censor: '***',\n * }\n *\n * // Remove fields entirely\n * redact: {\n * paths: ['temporary.data'],\n * remove: true,\n * }\n * ```\n */\nexport type RedactOptions =\n | string[]\n | {\n /** Paths to redact using dot notation or bracket notation for special chars */\n paths: string[];\n /** Custom replacement text (default: '[REDACTED]') */\n censor?: string | ((value: unknown, path: string[]) => unknown);\n /** Remove the field entirely instead of replacing (default: false) */\n remove?: boolean;\n /**\n * How to combine custom paths with default sensitive paths.\n * - 'merge': Custom paths are added to default paths (default)\n * - 'override': Only custom paths are used, defaults are ignored\n */\n resolution?: 'merge' | 'override';\n };\n\nexport type CreateLoggerOptions = {\n /** Enable pretty printing with colors (disabled in production) */\n pretty?: boolean;\n /** Minimum log level to output */\n level?: LogLevel;\n /**\n * Redaction configuration for masking sensitive data.\n *\n * - `true`: Uses default sensitive paths (password, token, secret, etc.)\n * - `false` or `undefined`: No redaction applied\n * - `string[]`: Custom paths merged with defaults\n * - `object`: Advanced config with paths, censor, remove, and resolution options\n *\n * By default, custom paths are **merged** with the default sensitive paths.\n * Use `resolution: 'override'` to disable defaults and use only your paths.\n *\n * @example\n * ```typescript\n * // Use defaults only\n * createLogger({ redact: true });\n *\n * // Add custom paths (merged with defaults)\n * createLogger({ redact: ['user.ssn', 'custom.field'] });\n *\n * // Override defaults completely\n * createLogger({\n * redact: {\n * paths: ['only.these.paths'],\n * resolution: 'override',\n * }\n * });\n *\n * // Merge with custom censor\n * createLogger({\n * redact: {\n * paths: ['extra.secret'],\n * censor: '***',\n * }\n * });\n * ```\n */\n redact?: boolean | RedactOptions;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkEA,IAAY,gDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AACD"}
package/dist/types.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { CreateLoggerOptions, LogFn, LogLevel, Logger } from "./types-DXdmn7h5.cjs";
2
- export { CreateLoggerOptions, LogFn, LogLevel, Logger };
1
+ import { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions } from "./types-JxCFymH0.cjs";
2
+ export { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions };
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { CreateLoggerOptions, LogFn, LogLevel, Logger } from "./types-C1RfRbo6.mjs";
2
- export { CreateLoggerOptions, LogFn, LogLevel, Logger };
1
+ import { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions } from "./types-BFiJzL9N.mjs";
2
+ export { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/logger",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "A simple and flexible logging library for Node.js and the browser",
5
5
  "private": false,
6
6
  "type": "module",
@@ -21,6 +21,10 @@
21
21
  "require": "./dist/console.cjs"
22
22
  }
23
23
  },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/geekmidas/toolbox"
27
+ },
24
28
  "publishConfig": {
25
29
  "registry": "https://registry.npmjs.org/",
26
30
  "access": "public"
@@ -277,7 +277,9 @@ describe('ConsoleLogger', () => {
277
277
  app: 'myApp',
278
278
  version: '1.0.0',
279
279
  });
280
- const childLogger = parentLogger.child({ module: 'auth' });
280
+ const childLogger = parentLogger.child({
281
+ module: 'auth',
282
+ }) as ConsoleLogger;
281
283
 
282
284
  expect(childLogger.data).toEqual({
283
285
  app: 'myApp',
@@ -308,7 +310,7 @@ describe('ConsoleLogger', () => {
308
310
  const childLogger = parentLogger.child({
309
311
  status: 'child',
310
312
  module: 'api',
311
- });
313
+ }) as ConsoleLogger;
312
314
 
313
315
  expect(childLogger.data).toEqual({
314
316
  env: 'dev',
@@ -338,7 +340,9 @@ describe('ConsoleLogger', () => {
338
340
 
339
341
  it('should not affect parent logger', () => {
340
342
  const parentLogger = new ConsoleLogger({ app: 'myApp' });
341
- const childLogger = parentLogger.child({ module: 'auth' });
343
+ const childLogger = parentLogger.child({
344
+ module: 'auth',
345
+ }) as ConsoleLogger;
342
346
 
343
347
  // Child logger has additional context
344
348
  expect(childLogger.data).toEqual({ app: 'myApp', module: 'auth' });
@@ -349,6 +353,29 @@ describe('ConsoleLogger', () => {
349
353
  });
350
354
 
351
355
  describe('Edge cases', () => {
356
+ it('should handle string-only logging without context object', () => {
357
+ const logger = new ConsoleLogger({ app: 'test' });
358
+
359
+ logger.info('Simple message without context object');
360
+
361
+ expect(console.info).toHaveBeenCalledWith(
362
+ { app: 'test', ts: 1234567890 },
363
+ 'Simple message without context object',
364
+ );
365
+ });
366
+
367
+ it('should handle string-only logging with child logger', () => {
368
+ const logger = new ConsoleLogger({ app: 'test' });
369
+ const child = logger.child({ module: 'auth' });
370
+
371
+ child.warn('Warning message');
372
+
373
+ expect(console.warn).toHaveBeenCalledWith(
374
+ { app: 'test', module: 'auth', ts: 1234567890 },
375
+ 'Warning message',
376
+ );
377
+ });
378
+
352
379
  it('should handle empty context object', () => {
353
380
  const logger = new ConsoleLogger();
354
381