@geekmidas/logger 0.1.0 → 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/dist/console.cjs CHANGED
@@ -1,53 +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) {
43
+ createLogFn(logMethod, level) {
20
44
  return (objOrMsg, msg, ...args) => {
45
+ if (!this.shouldLog(level)) return;
21
46
  const ts = Date.now();
22
47
  if (typeof objOrMsg === "string") {
23
- const mergedData$1 = {
48
+ const logData$1 = {
24
49
  ...this.data,
50
+ msg: objOrMsg,
25
51
  ts
26
52
  };
27
- logMethod(mergedData$1, objOrMsg, ...args);
53
+ logMethod(logData$1, ...args);
28
54
  return;
29
55
  }
30
- const mergedData = {
56
+ const logData = msg ? {
57
+ ...this.data,
58
+ ...objOrMsg,
59
+ msg,
60
+ ts
61
+ } : {
31
62
  ...this.data,
32
63
  ...objOrMsg,
33
64
  ts
34
65
  };
35
- if (msg) logMethod(mergedData, msg, ...args);
36
- else logMethod(mergedData, ...args);
66
+ logMethod(logData, ...args);
37
67
  };
38
68
  }
69
+ /** Trace level logging function */
70
+ trace = this.createLogFn(console.trace.bind(console), require_types.LogLevel.Trace);
39
71
  /** Debug level logging function */
40
- debug = this.createLogFn(console.debug.bind(console));
72
+ debug = this.createLogFn(console.debug.bind(console), require_types.LogLevel.Debug);
41
73
  /** Info level logging function */
42
- info = this.createLogFn(console.info.bind(console));
74
+ info = this.createLogFn(console.info.bind(console), require_types.LogLevel.Info);
43
75
  /** Warning level logging function */
44
- warn = this.createLogFn(console.warn.bind(console));
76
+ warn = this.createLogFn(console.warn.bind(console), require_types.LogLevel.Warn);
45
77
  /** Error level logging function */
46
- error = this.createLogFn(console.error.bind(console));
78
+ error = this.createLogFn(console.error.bind(console), require_types.LogLevel.Error);
47
79
  /** Fatal level logging function (uses console.error) */
48
- fatal = this.createLogFn(console.error.bind(console));
49
- /** Trace level logging function */
50
- trace = this.createLogFn(console.trace.bind(console));
80
+ fatal = this.createLogFn(console.error.bind(console), require_types.LogLevel.Fatal);
51
81
  /**
52
82
  * Creates a child logger with additional context data.
53
83
  * The child logger inherits all context from the parent and adds its own.
@@ -67,7 +97,7 @@ var ConsoleLogger = class ConsoleLogger {
67
97
  return new ConsoleLogger({
68
98
  ...this.data,
69
99
  ...obj
70
- });
100
+ }, this.level);
71
101
  }
72
102
  };
73
103
  /**
@@ -75,14 +105,14 @@ var ConsoleLogger = class ConsoleLogger {
75
105
  * ```typescript
76
106
  * const logger = new ConsoleLogger({ app: 'myApp' });
77
107
  * logger.info({ action: 'start' }, 'Application starting');
78
- * // Logs: { app: 'myApp', action: 'start', ts: 1234567890 } Application starting
108
+ * // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
79
109
  * ```
80
110
  *
81
111
  * @example Child logger usage
82
112
  * ```typescript
83
113
  * const childLogger = logger.child({ module: 'auth' });
84
114
  * childLogger.debug({ userId: 123 }, 'User authenticated');
85
- * // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 } User authenticated
115
+ * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
86
116
  * ```
87
117
  *
88
118
  * @example Error logging with context
@@ -104,13 +134,15 @@ const DEFAULT_LOGGER = new ConsoleLogger();
104
134
  * @example
105
135
  * ```typescript
106
136
  * import { createLogger } from '@geekmidas/logger/console';
137
+ * import { LogLevel } from '@geekmidas/logger';
107
138
  *
108
139
  * const logger = createLogger({ level: LogLevel.Debug });
109
- * logger.info({ action: 'start' }, 'Application starting');
140
+ * logger.debug('This will be logged');
141
+ * logger.trace('This will NOT be logged (below Debug level)');
110
142
  * ```
111
143
  */
112
144
  function createLogger(options = {}) {
113
- return new ConsoleLogger();
145
+ return new ConsoleLogger({}, options.level ?? require_types.LogLevel.Info);
114
146
  }
115
147
 
116
148
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"console.cjs","names":["data: object","logMethod: (...args: any[]) => void","objOrMsg: T | string","msg?: string","mergedData","obj: object","options: CreateLoggerOptions"],"sources":["../src/console.ts"],"sourcesContent":["import type { CreateLoggerOptions, LogFn, Logger } from './types';\n\nexport class ConsoleLogger implements Logger {\n /**\n * Creates a new ConsoleLogger instance.\n *\n * @param data - Initial context data to include in all log messages\n */\n constructor(readonly data: object = {}) {}\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 * @returns A LogFn that handles both structured and simple logging\n * @private\n */\n private createLogFn(logMethod: (...args: any[]) => void): LogFn {\n return <T extends object>(\n objOrMsg: T | string,\n msg?: string,\n ...args: any[]\n ): void => {\n const ts = Date.now();\n\n // Handle simple string logging: logger.info('message')\n if (typeof objOrMsg === 'string') {\n const mergedData = { ...this.data, ts };\n logMethod(mergedData, objOrMsg, ...args);\n return;\n }\n\n // Handle structured logging: logger.info({ data }, 'message')\n const mergedData = { ...this.data, ...objOrMsg, ts };\n if (msg) {\n logMethod(mergedData, msg, ...args);\n } else {\n logMethod(mergedData, ...args);\n }\n };\n }\n\n /** Debug level logging function */\n debug: LogFn = this.createLogFn(console.debug.bind(console));\n /** Info level logging function */\n info: LogFn = this.createLogFn(console.info.bind(console));\n /** Warning level logging function */\n warn: LogFn = this.createLogFn(console.warn.bind(console));\n /** Error level logging function */\n error: LogFn = this.createLogFn(console.error.bind(console));\n /** Fatal level logging function (uses console.error) */\n fatal: LogFn = this.createLogFn(console.error.bind(console));\n /** Trace level logging function */\n trace: LogFn = this.createLogFn(console.trace.bind(console));\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 ...this.data,\n ...obj,\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', ts: 1234567890 } Application starting\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, ts: 1234567891 } User authenticated\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 *\n * const logger = createLogger({ level: LogLevel.Debug });\n * logger.info({ action: 'start' }, 'Application starting');\n * ```\n */\nexport function createLogger(options: CreateLoggerOptions = {}): Logger {\n return new ConsoleLogger();\n}\n"],"mappings":";;AAEA,IAAa,gBAAb,MAAa,cAAgC;;;;;;CAM3C,YAAqBA,OAAe,CAAE,GAAE;EAAnB;CAAqB;;;;;;;;CAS1C,AAAQ,YAAYC,WAA4C;AAC9D,SAAO,CACLC,UACAC,KACA,GAAG,SACM;GACT,MAAM,KAAK,KAAK,KAAK;AAGrB,cAAW,aAAa,UAAU;IAChC,MAAMC,eAAa;KAAE,GAAG,KAAK;KAAM;IAAI;AACvC,cAAUA,cAAY,UAAU,GAAG,KAAK;AACxC;GACD;GAGD,MAAM,aAAa;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;GAAI;AACpD,OAAI,IACF,WAAU,YAAY,KAAK,GAAG,KAAK;OAEnC,WAAU,YAAY,GAAG,KAAK;EAEjC;CACF;;CAGD,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,CAAC;;CAE1D,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,CAAC;;CAE1D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;;;;;;;;;;;;;;;CAiB5D,MAAMC,KAAqB;AACzB,SAAO,IAAI,cAAc;GACvB,GAAG,KAAK;GACR,GAAG;EACJ;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA2BD,MAAa,iBAAiB,IAAI;;;;;;;;;;;;;;;AAgBlC,SAAgB,aAAaC,UAA+B,CAAE,GAAU;AACtE,QAAO,IAAI;AACZ"}
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"}
@@ -1,22 +1,31 @@
1
- import { CreateLoggerOptions, LogFn, Logger } from "./types-JxCFymH0.cjs";
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 } Application starting
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 } User authenticated
68
+ * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
62
69
  * ```
63
70
  *
64
71
  * @example Error logging with context
@@ -80,9 +87,11 @@ declare const DEFAULT_LOGGER: any;
80
87
  * @example
81
88
  * ```typescript
82
89
  * import { createLogger } from '@geekmidas/logger/console';
90
+ * import { LogLevel } from '@geekmidas/logger';
83
91
  *
84
92
  * const logger = createLogger({ level: LogLevel.Debug });
85
- * logger.info({ action: 'start' }, 'Application starting');
93
+ * logger.debug('This will be logged');
94
+ * logger.trace('This will NOT be logged (below Debug level)');
86
95
  * ```
87
96
  */
88
97
  declare function createLogger(options?: CreateLoggerOptions): Logger;
@@ -1,22 +1,31 @@
1
- import { CreateLoggerOptions, LogFn, Logger } from "./types-BFiJzL9N.mjs";
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 } Application starting
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 } User authenticated
68
+ * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
62
69
  * ```
63
70
  *
64
71
  * @example Error logging with context
@@ -80,9 +87,11 @@ declare const DEFAULT_LOGGER: any;
80
87
  * @example
81
88
  * ```typescript
82
89
  * import { createLogger } from '@geekmidas/logger/console';
90
+ * import { LogLevel } from '@geekmidas/logger';
83
91
  *
84
92
  * const logger = createLogger({ level: LogLevel.Debug });
85
- * logger.info({ action: 'start' }, 'Application starting');
93
+ * logger.debug('This will be logged');
94
+ * logger.trace('This will NOT be logged (below Debug level)');
86
95
  * ```
87
96
  */
88
97
  declare function createLogger(options?: CreateLoggerOptions): Logger;
package/dist/console.mjs CHANGED
@@ -1,52 +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) {
43
+ createLogFn(logMethod, level) {
19
44
  return (objOrMsg, msg, ...args) => {
45
+ if (!this.shouldLog(level)) return;
20
46
  const ts = Date.now();
21
47
  if (typeof objOrMsg === "string") {
22
- const mergedData$1 = {
48
+ const logData$1 = {
23
49
  ...this.data,
50
+ msg: objOrMsg,
24
51
  ts
25
52
  };
26
- logMethod(mergedData$1, objOrMsg, ...args);
53
+ logMethod(logData$1, ...args);
27
54
  return;
28
55
  }
29
- const mergedData = {
56
+ const logData = msg ? {
57
+ ...this.data,
58
+ ...objOrMsg,
59
+ msg,
60
+ ts
61
+ } : {
30
62
  ...this.data,
31
63
  ...objOrMsg,
32
64
  ts
33
65
  };
34
- if (msg) logMethod(mergedData, msg, ...args);
35
- else logMethod(mergedData, ...args);
66
+ logMethod(logData, ...args);
36
67
  };
37
68
  }
69
+ /** Trace level logging function */
70
+ trace = this.createLogFn(console.trace.bind(console), LogLevel.Trace);
38
71
  /** Debug level logging function */
39
- debug = this.createLogFn(console.debug.bind(console));
72
+ debug = this.createLogFn(console.debug.bind(console), LogLevel.Debug);
40
73
  /** Info level logging function */
41
- info = this.createLogFn(console.info.bind(console));
74
+ info = this.createLogFn(console.info.bind(console), LogLevel.Info);
42
75
  /** Warning level logging function */
43
- warn = this.createLogFn(console.warn.bind(console));
76
+ warn = this.createLogFn(console.warn.bind(console), LogLevel.Warn);
44
77
  /** Error level logging function */
45
- error = this.createLogFn(console.error.bind(console));
78
+ error = this.createLogFn(console.error.bind(console), LogLevel.Error);
46
79
  /** Fatal level logging function (uses console.error) */
47
- fatal = this.createLogFn(console.error.bind(console));
48
- /** Trace level logging function */
49
- trace = this.createLogFn(console.trace.bind(console));
80
+ fatal = this.createLogFn(console.error.bind(console), LogLevel.Fatal);
50
81
  /**
51
82
  * Creates a child logger with additional context data.
52
83
  * The child logger inherits all context from the parent and adds its own.
@@ -66,7 +97,7 @@ var ConsoleLogger = class ConsoleLogger {
66
97
  return new ConsoleLogger({
67
98
  ...this.data,
68
99
  ...obj
69
- });
100
+ }, this.level);
70
101
  }
71
102
  };
72
103
  /**
@@ -74,14 +105,14 @@ var ConsoleLogger = class ConsoleLogger {
74
105
  * ```typescript
75
106
  * const logger = new ConsoleLogger({ app: 'myApp' });
76
107
  * logger.info({ action: 'start' }, 'Application starting');
77
- * // Logs: { app: 'myApp', action: 'start', ts: 1234567890 } Application starting
108
+ * // Logs: { app: 'myApp', action: 'start', msg: 'Application starting', ts: 1234567890 }
78
109
  * ```
79
110
  *
80
111
  * @example Child logger usage
81
112
  * ```typescript
82
113
  * const childLogger = logger.child({ module: 'auth' });
83
114
  * childLogger.debug({ userId: 123 }, 'User authenticated');
84
- * // Logs: { app: 'myApp', module: 'auth', userId: 123, ts: 1234567891 } User authenticated
115
+ * // Logs: { app: 'myApp', module: 'auth', userId: 123, msg: 'User authenticated', ts: 1234567891 }
85
116
  * ```
86
117
  *
87
118
  * @example Error logging with context
@@ -103,13 +134,15 @@ const DEFAULT_LOGGER = new ConsoleLogger();
103
134
  * @example
104
135
  * ```typescript
105
136
  * import { createLogger } from '@geekmidas/logger/console';
137
+ * import { LogLevel } from '@geekmidas/logger';
106
138
  *
107
139
  * const logger = createLogger({ level: LogLevel.Debug });
108
- * logger.info({ action: 'start' }, 'Application starting');
140
+ * logger.debug('This will be logged');
141
+ * logger.trace('This will NOT be logged (below Debug level)');
109
142
  * ```
110
143
  */
111
144
  function createLogger(options = {}) {
112
- return new ConsoleLogger();
145
+ return new ConsoleLogger({}, options.level ?? LogLevel.Info);
113
146
  }
114
147
 
115
148
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"console.mjs","names":["data: object","logMethod: (...args: any[]) => void","objOrMsg: T | string","msg?: string","mergedData","obj: object","options: CreateLoggerOptions"],"sources":["../src/console.ts"],"sourcesContent":["import type { CreateLoggerOptions, LogFn, Logger } from './types';\n\nexport class ConsoleLogger implements Logger {\n /**\n * Creates a new ConsoleLogger instance.\n *\n * @param data - Initial context data to include in all log messages\n */\n constructor(readonly data: object = {}) {}\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 * @returns A LogFn that handles both structured and simple logging\n * @private\n */\n private createLogFn(logMethod: (...args: any[]) => void): LogFn {\n return <T extends object>(\n objOrMsg: T | string,\n msg?: string,\n ...args: any[]\n ): void => {\n const ts = Date.now();\n\n // Handle simple string logging: logger.info('message')\n if (typeof objOrMsg === 'string') {\n const mergedData = { ...this.data, ts };\n logMethod(mergedData, objOrMsg, ...args);\n return;\n }\n\n // Handle structured logging: logger.info({ data }, 'message')\n const mergedData = { ...this.data, ...objOrMsg, ts };\n if (msg) {\n logMethod(mergedData, msg, ...args);\n } else {\n logMethod(mergedData, ...args);\n }\n };\n }\n\n /** Debug level logging function */\n debug: LogFn = this.createLogFn(console.debug.bind(console));\n /** Info level logging function */\n info: LogFn = this.createLogFn(console.info.bind(console));\n /** Warning level logging function */\n warn: LogFn = this.createLogFn(console.warn.bind(console));\n /** Error level logging function */\n error: LogFn = this.createLogFn(console.error.bind(console));\n /** Fatal level logging function (uses console.error) */\n fatal: LogFn = this.createLogFn(console.error.bind(console));\n /** Trace level logging function */\n trace: LogFn = this.createLogFn(console.trace.bind(console));\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 ...this.data,\n ...obj,\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', ts: 1234567890 } Application starting\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, ts: 1234567891 } User authenticated\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 *\n * const logger = createLogger({ level: LogLevel.Debug });\n * logger.info({ action: 'start' }, 'Application starting');\n * ```\n */\nexport function createLogger(options: CreateLoggerOptions = {}): Logger {\n return new ConsoleLogger();\n}\n"],"mappings":";AAEA,IAAa,gBAAb,MAAa,cAAgC;;;;;;CAM3C,YAAqBA,OAAe,CAAE,GAAE;EAAnB;CAAqB;;;;;;;;CAS1C,AAAQ,YAAYC,WAA4C;AAC9D,SAAO,CACLC,UACAC,KACA,GAAG,SACM;GACT,MAAM,KAAK,KAAK,KAAK;AAGrB,cAAW,aAAa,UAAU;IAChC,MAAMC,eAAa;KAAE,GAAG,KAAK;KAAM;IAAI;AACvC,cAAUA,cAAY,UAAU,GAAG,KAAK;AACxC;GACD;GAGD,MAAM,aAAa;IAAE,GAAG,KAAK;IAAM,GAAG;IAAU;GAAI;AACpD,OAAI,IACF,WAAU,YAAY,KAAK,GAAG,KAAK;OAEnC,WAAU,YAAY,GAAG,KAAK;EAEjC;CACF;;CAGD,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,CAAC;;CAE1D,OAAc,KAAK,YAAY,QAAQ,KAAK,KAAK,QAAQ,CAAC;;CAE1D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;CAE5D,QAAe,KAAK,YAAY,QAAQ,MAAM,KAAK,QAAQ,CAAC;;;;;;;;;;;;;;;;CAiB5D,MAAMC,KAAqB;AACzB,SAAO,IAAI,cAAc;GACvB,GAAG,KAAK;GACR,GAAG;EACJ;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA2BD,MAAa,iBAAiB,IAAI;;;;;;;;;;;;;;;AAgBlC,SAAgB,aAAaC,UAA+B,CAAE,GAAU;AACtE,QAAO,IAAI;AACZ"}
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"}
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions } from "./types-BFiJzL9N.mjs";
1
+ import { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions } from "./types-Bga8WDuP.mjs";
2
2
  export { CreateLoggerOptions, LogFn, LogLevel, Logger, RedactOptions };
package/dist/pino.cjs CHANGED
@@ -21,72 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
+ const require_redact_paths = require('./redact-paths-D0m0DIuQ.cjs');
24
25
  const pino = __toESM(require("pino"));
25
26
 
26
27
  //#region src/pino.ts
27
28
  /**
28
- * Default sensitive field paths for redaction.
29
- *
30
- * These paths are automatically used when `redact: true` is set,
31
- * and merged with custom paths unless `resolution: 'override'` is specified.
32
- *
33
- * Includes:
34
- * - Authentication: password, token, apiKey, authorization, credentials
35
- * - Headers: authorization, cookie, x-api-key, x-auth-token
36
- * - Personal data: ssn, creditCard, cvv, pin
37
- * - Secrets: secret, connectionString, databaseUrl
38
- * - Wildcards: *.password, *.secret, *.token (catches nested fields)
39
- */
40
- const DEFAULT_REDACT_PATHS = [
41
- "password",
42
- "pass",
43
- "passwd",
44
- "secret",
45
- "token",
46
- "accessToken",
47
- "refreshToken",
48
- "idToken",
49
- "apiKey",
50
- "api_key",
51
- "apikey",
52
- "auth",
53
- "authorization",
54
- "credential",
55
- "credentials",
56
- "*.password",
57
- "*.secret",
58
- "*.token",
59
- "*.apiKey",
60
- "*.api_key",
61
- "*.authorization",
62
- "*.accessToken",
63
- "*.refreshToken",
64
- "headers.authorization",
65
- "headers.Authorization",
66
- "headers[\"authorization\"]",
67
- "headers[\"Authorization\"]",
68
- "headers.cookie",
69
- "headers.Cookie",
70
- "headers[\"x-api-key\"]",
71
- "headers[\"X-Api-Key\"]",
72
- "headers[\"x-auth-token\"]",
73
- "headers[\"X-Auth-Token\"]",
74
- "ssn",
75
- "socialSecurityNumber",
76
- "social_security_number",
77
- "creditCard",
78
- "credit_card",
79
- "cardNumber",
80
- "card_number",
81
- "cvv",
82
- "cvc",
83
- "pin",
84
- "connectionString",
85
- "connection_string",
86
- "databaseUrl",
87
- "database_url"
88
- ];
89
- /**
90
29
  * Resolves redaction configuration from options.
91
30
  * Returns undefined if redaction is disabled, or a pino-compatible redact config.
92
31
  *
@@ -95,10 +34,10 @@ const DEFAULT_REDACT_PATHS = [
95
34
  */
96
35
  function resolveRedactConfig(redact) {
97
36
  if (redact === void 0 || redact === false) return void 0;
98
- if (redact === true) return DEFAULT_REDACT_PATHS;
99
- if (Array.isArray(redact)) return [...DEFAULT_REDACT_PATHS, ...redact];
37
+ if (redact === true) return require_redact_paths.DEFAULT_REDACT_PATHS;
38
+ if (Array.isArray(redact)) return [...require_redact_paths.DEFAULT_REDACT_PATHS, ...redact];
100
39
  const { resolution = "merge", paths, censor, remove } = redact;
101
- const resolvedPaths = resolution === "override" ? paths : [...DEFAULT_REDACT_PATHS, ...paths];
40
+ const resolvedPaths = resolution === "override" ? paths : [...require_redact_paths.DEFAULT_REDACT_PATHS, ...paths];
102
41
  const config = { paths: resolvedPaths };
103
42
  if (censor !== void 0) config.censor = censor;
104
43
  if (remove !== void 0) config.remove = remove;
@@ -145,6 +84,6 @@ function createLogger(options = {}) {
145
84
  }
146
85
 
147
86
  //#endregion
148
- exports.DEFAULT_REDACT_PATHS = DEFAULT_REDACT_PATHS;
87
+ exports.DEFAULT_REDACT_PATHS = require_redact_paths.DEFAULT_REDACT_PATHS;
149
88
  exports.createLogger = createLogger;
150
89
  //# sourceMappingURL=pino.cjs.map
package/dist/pino.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pino.cjs","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,eAAK;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"}
1
+ {"version":3,"file":"pino.cjs","names":["redact: boolean | RedactOptions | undefined","DEFAULT_REDACT_PATHS","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 { DEFAULT_REDACT_PATHS } from './redact-paths';\nimport type { CreateLoggerOptions, RedactOptions } from './types';\n\n// Re-export for backwards compatibility\nexport { DEFAULT_REDACT_PATHS } from './redact-paths';\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAS,oBACPA,QAC8B;AAC9B,KAAI,qBAAwB,WAAW,MACrC;AAGF,KAAI,WAAW,KACb,QAAOC;AAIT,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,CAAC,GAAGA,2CAAsB,GAAG,MAAO;CAI7C,MAAM,EAAE,aAAa,SAAS,OAAO,QAAQ,QAAQ,GAAG;CAExD,MAAM,gBACJ,eAAe,aAAa,QAAQ,CAAC,GAAGA,2CAAsB,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,eAAK;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"}
package/dist/pino.d.cts CHANGED
@@ -1,22 +1,9 @@
1
1
  import { CreateLoggerOptions } from "./types-JxCFymH0.cjs";
2
+ import { DEFAULT_REDACT_PATHS } from "./redact-paths-Br-tI2GZ.cjs";
2
3
  import * as pino0 from "pino";
3
4
 
4
5
  //#region src/pino.d.ts
5
6
 
6
- /**
7
- * Default sensitive field paths for redaction.
8
- *
9
- * These paths are automatically used when `redact: true` is set,
10
- * and merged with custom paths unless `resolution: 'override'` is specified.
11
- *
12
- * Includes:
13
- * - Authentication: password, token, apiKey, authorization, credentials
14
- * - Headers: authorization, cookie, x-api-key, x-auth-token
15
- * - Personal data: ssn, creditCard, cvv, pin
16
- * - Secrets: secret, connectionString, databaseUrl
17
- * - Wildcards: *.password, *.secret, *.token (catches nested fields)
18
- */
19
- declare const DEFAULT_REDACT_PATHS: string[];
20
7
  /**
21
8
  * Creates a pino logger instance with optional redaction support.
22
9
  *