@geekmidas/logger 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +315 -0
- package/dist/console.cjs +94 -0
- package/dist/console.cjs.map +1 -0
- package/dist/console.d.cts +76 -0
- package/dist/console.d.mts +76 -0
- package/dist/console.mjs +92 -0
- package/dist/console.mjs.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/pino.cjs +48 -0
- package/dist/pino.cjs.map +1 -0
- package/dist/pino.d.cts +8 -0
- package/dist/pino.d.mts +8 -0
- package/dist/pino.mjs +25 -0
- package/dist/pino.mjs.map +1 -0
- package/dist/types-C1RfRbo6.d.mts +81 -0
- package/dist/types-DXdmn7h5.d.cts +81 -0
- package/dist/types-ag_0Cvbg.cjs +38 -0
- package/dist/types-ag_0Cvbg.cjs.map +1 -0
- package/dist/types-yQ6XOihF.mjs +32 -0
- package/dist/types-yQ6XOihF.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/package.json +34 -0
- package/src/__tests__/console.spec.ts +526 -0
- package/src/__tests__/pino.spec.ts +156 -0
- package/src/console.ts +93 -0
- package/src/index.ts +6 -0
- package/src/pino.ts +26 -0
- package/src/types.ts +80 -0
- package/tsdown.config.ts +3 -0
package/dist/pino.cjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const pino = __toESM(require("pino"));
|
|
25
|
+
|
|
26
|
+
//#region src/pino.ts
|
|
27
|
+
function createLogger(options) {
|
|
28
|
+
const pretty = options?.pretty && process.NODE_ENV !== "production";
|
|
29
|
+
const baseOptions = pretty ? { transport: {
|
|
30
|
+
target: "pino-pretty",
|
|
31
|
+
options: { colorize: true }
|
|
32
|
+
} } : {};
|
|
33
|
+
return (0, pino.pino)({
|
|
34
|
+
...baseOptions,
|
|
35
|
+
formatters: {
|
|
36
|
+
bindings() {
|
|
37
|
+
return { nodeVersion: process.version };
|
|
38
|
+
},
|
|
39
|
+
level: (label) => {
|
|
40
|
+
return { level: label.toUpperCase() };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.createLogger = createLogger;
|
|
48
|
+
//# sourceMappingURL=pino.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pino.cjs","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,eAAK;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"}
|
package/dist/pino.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateLoggerOptions } from "./types-DXdmn7h5.cjs";
|
|
2
|
+
import * as pino0 from "pino";
|
|
3
|
+
|
|
4
|
+
//#region src/pino.d.ts
|
|
5
|
+
declare function createLogger(options: CreateLoggerOptions): pino0.Logger<never, boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createLogger };
|
|
8
|
+
//# sourceMappingURL=pino.d.cts.map
|
package/dist/pino.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreateLoggerOptions } from "./types-C1RfRbo6.mjs";
|
|
2
|
+
import * as pino0 from "pino";
|
|
3
|
+
|
|
4
|
+
//#region src/pino.d.ts
|
|
5
|
+
declare function createLogger(options: CreateLoggerOptions): pino0.Logger<never, boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createLogger };
|
|
8
|
+
//# sourceMappingURL=pino.d.mts.map
|
package/dist/pino.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { pino } from "pino";
|
|
2
|
+
|
|
3
|
+
//#region src/pino.ts
|
|
4
|
+
function createLogger(options) {
|
|
5
|
+
const pretty = options?.pretty && process.NODE_ENV !== "production";
|
|
6
|
+
const baseOptions = pretty ? { transport: {
|
|
7
|
+
target: "pino-pretty",
|
|
8
|
+
options: { colorize: true }
|
|
9
|
+
} } : {};
|
|
10
|
+
return pino({
|
|
11
|
+
...baseOptions,
|
|
12
|
+
formatters: {
|
|
13
|
+
bindings() {
|
|
14
|
+
return { nodeVersion: process.version };
|
|
15
|
+
},
|
|
16
|
+
level: (label) => {
|
|
17
|
+
return { level: label.toUpperCase() };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createLogger };
|
|
25
|
+
//# sourceMappingURL=pino.mjs.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Logging function type that supports both structured and simple logging.
|
|
4
|
+
* Can be called with an object for structured logging or just a message string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Structured logging with context object
|
|
9
|
+
* logger.info({ userId: 123, action: 'login' }, 'User logged in');
|
|
10
|
+
*
|
|
11
|
+
* // Simple string logging
|
|
12
|
+
* logger.info('Application started');
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
type LogFn = {
|
|
16
|
+
/** Structured logging with context object, optional message, and additional arguments */
|
|
17
|
+
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
18
|
+
/** Simple string logging */
|
|
19
|
+
(msg: string): void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Standard logger interface with multiple log levels and child logger support.
|
|
23
|
+
* Follows common logging patterns with structured logging capabilities.
|
|
24
|
+
*
|
|
25
|
+
* @interface Logger
|
|
26
|
+
*/
|
|
27
|
+
interface Logger {
|
|
28
|
+
/** Debug level logging - verbose information for debugging */
|
|
29
|
+
debug: LogFn;
|
|
30
|
+
/** Info level logging - general informational messages */
|
|
31
|
+
info: LogFn;
|
|
32
|
+
/** Warning level logging - potentially harmful situations */
|
|
33
|
+
warn: LogFn;
|
|
34
|
+
/** Error level logging - error events that might still allow the application to continue */
|
|
35
|
+
error: LogFn;
|
|
36
|
+
/** Fatal level logging - severe errors that will likely cause the application to abort */
|
|
37
|
+
fatal: LogFn;
|
|
38
|
+
/** Trace level logging - most detailed information */
|
|
39
|
+
trace: LogFn;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a child logger with additional context.
|
|
42
|
+
* Child loggers inherit parent context and add their own.
|
|
43
|
+
*
|
|
44
|
+
* @param obj - Additional context to include in all child logger calls
|
|
45
|
+
* @returns A new Logger instance with merged context
|
|
46
|
+
*/
|
|
47
|
+
child: (obj: object) => Logger;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Console-based logger implementation that outputs to standard console methods.
|
|
51
|
+
* Supports structured logging with automatic timestamp injection and context inheritance.
|
|
52
|
+
*
|
|
53
|
+
* @implements {Logger}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });
|
|
58
|
+
* logger.info({ userId: 123 }, 'User action performed');
|
|
59
|
+
* // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed
|
|
60
|
+
*
|
|
61
|
+
* const childLogger = logger.child({ module: 'auth' });
|
|
62
|
+
* childLogger.debug({ action: 'validate' }, 'Validating token');
|
|
63
|
+
* // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare enum LogLevel {
|
|
67
|
+
Trace = "trace",
|
|
68
|
+
Debug = "debug",
|
|
69
|
+
Info = "info",
|
|
70
|
+
Warn = "warn",
|
|
71
|
+
Error = "error",
|
|
72
|
+
Fatal = "fatal",
|
|
73
|
+
Silent = "silent",
|
|
74
|
+
}
|
|
75
|
+
type CreateLoggerOptions = {
|
|
76
|
+
pretty?: boolean;
|
|
77
|
+
level?: LogLevel;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { CreateLoggerOptions, LogFn, LogLevel, Logger };
|
|
81
|
+
//# sourceMappingURL=types-C1RfRbo6.d.mts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Logging function type that supports both structured and simple logging.
|
|
4
|
+
* Can be called with an object for structured logging or just a message string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Structured logging with context object
|
|
9
|
+
* logger.info({ userId: 123, action: 'login' }, 'User logged in');
|
|
10
|
+
*
|
|
11
|
+
* // Simple string logging
|
|
12
|
+
* logger.info('Application started');
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
type LogFn = {
|
|
16
|
+
/** Structured logging with context object, optional message, and additional arguments */
|
|
17
|
+
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
18
|
+
/** Simple string logging */
|
|
19
|
+
(msg: string): void;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Standard logger interface with multiple log levels and child logger support.
|
|
23
|
+
* Follows common logging patterns with structured logging capabilities.
|
|
24
|
+
*
|
|
25
|
+
* @interface Logger
|
|
26
|
+
*/
|
|
27
|
+
interface Logger {
|
|
28
|
+
/** Debug level logging - verbose information for debugging */
|
|
29
|
+
debug: LogFn;
|
|
30
|
+
/** Info level logging - general informational messages */
|
|
31
|
+
info: LogFn;
|
|
32
|
+
/** Warning level logging - potentially harmful situations */
|
|
33
|
+
warn: LogFn;
|
|
34
|
+
/** Error level logging - error events that might still allow the application to continue */
|
|
35
|
+
error: LogFn;
|
|
36
|
+
/** Fatal level logging - severe errors that will likely cause the application to abort */
|
|
37
|
+
fatal: LogFn;
|
|
38
|
+
/** Trace level logging - most detailed information */
|
|
39
|
+
trace: LogFn;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a child logger with additional context.
|
|
42
|
+
* Child loggers inherit parent context and add their own.
|
|
43
|
+
*
|
|
44
|
+
* @param obj - Additional context to include in all child logger calls
|
|
45
|
+
* @returns A new Logger instance with merged context
|
|
46
|
+
*/
|
|
47
|
+
child: (obj: object) => Logger;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Console-based logger implementation that outputs to standard console methods.
|
|
51
|
+
* Supports structured logging with automatic timestamp injection and context inheritance.
|
|
52
|
+
*
|
|
53
|
+
* @implements {Logger}
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });
|
|
58
|
+
* logger.info({ userId: 123 }, 'User action performed');
|
|
59
|
+
* // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed
|
|
60
|
+
*
|
|
61
|
+
* const childLogger = logger.child({ module: 'auth' });
|
|
62
|
+
* childLogger.debug({ action: 'validate' }, 'Validating token');
|
|
63
|
+
* // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare enum LogLevel {
|
|
67
|
+
Trace = "trace",
|
|
68
|
+
Debug = "debug",
|
|
69
|
+
Info = "info",
|
|
70
|
+
Warn = "warn",
|
|
71
|
+
Error = "error",
|
|
72
|
+
Fatal = "fatal",
|
|
73
|
+
Silent = "silent",
|
|
74
|
+
}
|
|
75
|
+
type CreateLoggerOptions = {
|
|
76
|
+
pretty?: boolean;
|
|
77
|
+
level?: LogLevel;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { CreateLoggerOptions, LogFn, LogLevel, Logger };
|
|
81
|
+
//# sourceMappingURL=types-DXdmn7h5.d.cts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/types.ts
|
|
3
|
+
/**
|
|
4
|
+
* Console-based logger implementation that outputs to standard console methods.
|
|
5
|
+
* Supports structured logging with automatic timestamp injection and context inheritance.
|
|
6
|
+
*
|
|
7
|
+
* @implements {Logger}
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });
|
|
12
|
+
* logger.info({ userId: 123 }, 'User action performed');
|
|
13
|
+
* // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed
|
|
14
|
+
*
|
|
15
|
+
* const childLogger = logger.child({ module: 'auth' });
|
|
16
|
+
* childLogger.debug({ action: 'validate' }, 'Validating token');
|
|
17
|
+
* // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
21
|
+
LogLevel$1["Trace"] = "trace";
|
|
22
|
+
LogLevel$1["Debug"] = "debug";
|
|
23
|
+
LogLevel$1["Info"] = "info";
|
|
24
|
+
LogLevel$1["Warn"] = "warn";
|
|
25
|
+
LogLevel$1["Error"] = "error";
|
|
26
|
+
LogLevel$1["Fatal"] = "fatal";
|
|
27
|
+
LogLevel$1["Silent"] = "silent";
|
|
28
|
+
return LogLevel$1;
|
|
29
|
+
}({});
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
Object.defineProperty(exports, 'LogLevel', {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return LogLevel;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=types-ag_0Cvbg.cjs.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Console-based logger implementation that outputs to standard console methods.
|
|
4
|
+
* Supports structured logging with automatic timestamp injection and context inheritance.
|
|
5
|
+
*
|
|
6
|
+
* @implements {Logger}
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const logger = new ConsoleLogger({ app: 'myApp', version: '1.0.0' });
|
|
11
|
+
* logger.info({ userId: 123 }, 'User action performed');
|
|
12
|
+
* // Output: { app: 'myApp', version: '1.0.0', userId: 123, ts: 1234567890 } User action performed
|
|
13
|
+
*
|
|
14
|
+
* const childLogger = logger.child({ module: 'auth' });
|
|
15
|
+
* childLogger.debug({ action: 'validate' }, 'Validating token');
|
|
16
|
+
* // Output: { app: 'myApp', version: '1.0.0', module: 'auth', action: 'validate', ts: 1234567891 } Validating token
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
20
|
+
LogLevel$1["Trace"] = "trace";
|
|
21
|
+
LogLevel$1["Debug"] = "debug";
|
|
22
|
+
LogLevel$1["Info"] = "info";
|
|
23
|
+
LogLevel$1["Warn"] = "warn";
|
|
24
|
+
LogLevel$1["Error"] = "error";
|
|
25
|
+
LogLevel$1["Fatal"] = "fatal";
|
|
26
|
+
LogLevel$1["Silent"] = "silent";
|
|
27
|
+
return LogLevel$1;
|
|
28
|
+
}({});
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { LogLevel };
|
|
32
|
+
//# sourceMappingURL=types-yQ6XOihF.mjs.map
|
|
@@ -0,0 +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"}
|
package/dist/types.cjs
ADDED
package/dist/types.d.cts
ADDED
package/dist/types.d.mts
ADDED
package/dist/types.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geekmidas/logger",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A simple and flexible logging library for Node.js and the browser",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./pino": {
|
|
14
|
+
"types": "./dist/pino.d.ts",
|
|
15
|
+
"import": "./dist/pino.mjs",
|
|
16
|
+
"require": "./dist/pino.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./console": {
|
|
19
|
+
"types": "./dist/console.d.ts",
|
|
20
|
+
"import": "./dist/console.mjs",
|
|
21
|
+
"require": "./dist/console.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"registry": "https://registry.npmjs.org/",
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {},
|
|
29
|
+
"devDependencies": {},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"pino-pretty": "~13.1.2",
|
|
32
|
+
"pino": "~10.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|