@qianxude/logger 0.1.4

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.
@@ -0,0 +1,98 @@
1
+ import { BaseLogger } from '@qianxude/shared';
2
+ /**
3
+ * Minimal support that wraps pino to satisfy the LogSupport interface.
4
+ * Used as the delegate for BaseLogger.
5
+ */
6
+ class PinoSupport {
7
+ _pino;
8
+ constructor(_pino) {
9
+ this._pino = _pino;
10
+ }
11
+ get level() {
12
+ return this._pino.level;
13
+ }
14
+ setLevel(level) {
15
+ this._pino.level = level;
16
+ }
17
+ log(first, message, ctx) {
18
+ if (typeof first === 'string') {
19
+ this._pino[first](ctx ?? {}, message);
20
+ }
21
+ else {
22
+ const { level, message: msg, ...rest } = first;
23
+ this._pino[level](rest, msg);
24
+ }
25
+ }
26
+ }
27
+ /**
28
+ * Pino-backed logger that extends BaseLogger.
29
+ * Wraps a pino.Logger instance and provides stack-standard logging methods.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { createPrettyPino, PinoLogger } from '@qianxude/logger';
34
+ *
35
+ * const rawPino = createPrettyPino({ level: 'debug' });
36
+ * const logger = new PinoLogger(rawPino, { service: 'my-app' });
37
+ *
38
+ * logger.info('Application started');
39
+ * logger.error({ err: new Error('Oops') }, 'Something went wrong');
40
+ *
41
+ * const childLogger = logger.spawn({ requestId: 'abc-123' });
42
+ * childLogger.info('Processing request');
43
+ * ```
44
+ */
45
+ export class PinoLogger extends BaseLogger {
46
+ _pino;
47
+ _delegate;
48
+ /**
49
+ * Create a new PinoLogger wrapping a pino instance.
50
+ *
51
+ * @param pinoInstance - The underlying pino.Logger to wrap
52
+ * @param ctx - Initial context to attach to all log messages
53
+ */
54
+ constructor(pinoInstance, ctx = {}) {
55
+ super();
56
+ this._pino = pinoInstance;
57
+ this._delegate = new PinoSupport(pinoInstance);
58
+ this._ctx = ctx;
59
+ }
60
+ /**
61
+ * Get the underlying pino logger instance.
62
+ * Useful for advanced pino-specific operations.
63
+ */
64
+ get pino() {
65
+ return this._pino;
66
+ }
67
+ /**
68
+ * Create a child logger that extends the current context.
69
+ * The child logger shares the same pino instance but has its own context.
70
+ */
71
+ spawn(ctx) {
72
+ const child = Object.create(this.constructor.prototype);
73
+ child._ctx = { ...this._ctx, ...ctx };
74
+ child._delegate = this;
75
+ child._pino = this._pino;
76
+ return child;
77
+ }
78
+ }
79
+ /**
80
+ * Wrap a raw pino logger into a stack-standard Logger.
81
+ *
82
+ * @param pinoInstance - The pino.Logger instance to wrap
83
+ * @param ctx - Initial context to attach
84
+ * @returns A PinoLogger instance implementing the Logger interface
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import pino from 'pino';
89
+ * import { wrapPinoLogger } from '@qianxude/logger';
90
+ *
91
+ * const rawPino = pino({ level: 'info' });
92
+ * const logger = wrapPinoLogger(rawPino, { app: 'my-service' });
93
+ * ```
94
+ */
95
+ export function wrapPinoLogger(pinoInstance, ctx) {
96
+ return new PinoLogger(pinoInstance, ctx);
97
+ }
98
+ //# sourceMappingURL=pino-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino-logger.js","sourceRoot":"","sources":["../src/pino-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAiE,MAAM,kBAAkB,CAAC;AAE7G;;;GAGG;AACH,MAAM,WAAW;IACK;IAApB,YAAoB,KAAkB;QAAlB,UAAK,GAAL,KAAK,CAAa;IAAG,CAAC;IAE1C,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,KAAiB,CAAC;IACtC,CAAC;IAED,QAAQ,CAAC,KAAe;QACtB,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IAC3B,CAAC;IAID,GAAG,CAAC,KAA4B,EAAE,OAAgB,EAAE,GAAa;QAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI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ude/shared for convenience.
3
+ */
4
+ export type { Logger, LogLevel, Context, LevelEntry, Entry, GenericLog, LeveledLog } from '@qianxude/shared';
5
+ /**
6
+ * Type definitions for the logger package.
7
+ */
8
+ export type { PinoRollOptions, PinoRollLimitOptions } from './pino-roll.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE7G;;GAEG;AAEH,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Type definitions for pino-roll file rotation.
3
+ *
4
+ * pino-roll is a JS-only package without TypeScript exports.
5
+ * These types are based on pino-roll's documented API.
6
+ *
7
+ * @see https://github.com/mcollina/pino-roll#api
8
+ */
9
+ /**
10
+ * Options for limiting rotated log files.
11
+ */
12
+ export interface PinoRollLimitOptions {
13
+ /** Number of log files to keep (in addition to current file) */
14
+ count: number;
15
+ }
16
+ /**
17
+ * Options for pino-roll file rotation.
18
+ *
19
+ * Based on pino-roll's documented API.
20
+ * @see https://github.com/mcollina/pino-roll#api
21
+ */
22
+ export interface PinoRollOptions {
23
+ /** Absolute or relative path to the log file (required) */
24
+ file: string | (() => string);
25
+ /** Maximum size of a log file. Use 'k', 'm', 'g' for KB/MB/GB, or number for MB */
26
+ size?: string | number;
27
+ /** Time-based rotation: 'daily', 'hourly', or milliseconds */
28
+ frequency?: 'daily' | 'hourly' | number;
29
+ /** File extension to append after the number */
30
+ extension?: string;
31
+ /** Create symlink to current log file (default: true) */
32
+ symlink?: boolean;
33
+ /** Strategy to remove oldest files when rotating */
34
+ limit?: PinoRollLimitOptions;
35
+ /** Date format appended to filename (date-fns format, e.g., 'yyyy-MM-dd') */
36
+ dateFormat?: string;
37
+ /** Create parent directories if they don't exist (default: true) */
38
+ mkdir?: boolean;
39
+ }
40
+ //# sourceMappingURL=pino-roll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino-roll.d.ts","sourceRoot":"","sources":["../../src/types/pino-roll.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IAC9B,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IACxC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type definitions for pino-roll file rotation.
3
+ *
4
+ * pino-roll is a JS-only package without TypeScript exports.
5
+ * These types are based on pino-roll's documented API.
6
+ *
7
+ * @see https://github.com/mcollina/pino-roll#api
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=pino-roll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pino-roll.js","sourceRoot":"","sources":["../../src/types/pino-roll.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@qianxude/logger",
3
+ "version": "0.1.4",
4
+ "description": "Production-ready pino-based logger implementations for qianxude stack",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "dependencies": {
15
+ "@qianxude/shared": "~0.2.1",
16
+ "pino": "^9.6.0",
17
+ "pino-pretty": "^13.0.0",
18
+ "pino-roll": "^2.2.0"
19
+ },
20
+ "scripts": {
21
+ "build": "bun x tsc -p tsconfig.json",
22
+ "test": "bun test",
23
+ "typecheck": "bun x tsc -p tsconfig.json --noEmit",
24
+ "publish:pkg": "bun publish"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "engines": {
30
+ "node": ">=18",
31
+ "bun": ">=1.0.0"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ]
38
+ }