nest-logger-bundle 0.1.5
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/LICENSE +201 -0
- package/README.md +563 -0
- package/dist/lib/bundle/context/async-logger-context.service.d.ts +19 -0
- package/dist/lib/bundle/context/async-logger-context.service.js +101 -0
- package/dist/lib/bundle/context/async-logger-context.service.js.map +1 -0
- package/dist/lib/bundle/context/async-logger.hook.d.ts +10 -0
- package/dist/lib/bundle/context/async-logger.hook.js +14 -0
- package/dist/lib/bundle/context/async-logger.hook.js.map +1 -0
- package/dist/lib/bundle/context/logger.definitions.d.ts +4 -0
- package/dist/lib/bundle/context/logger.definitions.js +3 -0
- package/dist/lib/bundle/context/logger.definitions.js.map +1 -0
- package/dist/lib/bundle/dummy-logger.d.ts +18 -0
- package/dist/lib/bundle/dummy-logger.js +16 -0
- package/dist/lib/bundle/dummy-logger.js.map +1 -0
- package/dist/lib/bundle/index.d.ts +10 -0
- package/dist/lib/bundle/index.js +27 -0
- package/dist/lib/bundle/index.js.map +1 -0
- package/dist/lib/bundle/logger-branch/branch.utils.d.ts +10 -0
- package/dist/lib/bundle/logger-branch/branch.utils.js +32 -0
- package/dist/lib/bundle/logger-branch/branch.utils.js.map +1 -0
- package/dist/lib/bundle/logger-branch/logger-branch.d.ts +24 -0
- package/dist/lib/bundle/logger-branch/logger-branch.js +91 -0
- package/dist/lib/bundle/logger-branch/logger-branch.js.map +1 -0
- package/dist/lib/bundle/logger-branch/logger-leaf.d.ts +19 -0
- package/dist/lib/bundle/logger-branch/logger-leaf.js +27 -0
- package/dist/lib/bundle/logger-branch/logger-leaf.js.map +1 -0
- package/dist/lib/bundle/logger-branch/logger-node.d.ts +7 -0
- package/dist/lib/bundle/logger-branch/logger-node.js +3 -0
- package/dist/lib/bundle/logger-branch/logger-node.js.map +1 -0
- package/dist/lib/bundle/logger-bundle.module.d.ts +2 -0
- package/dist/lib/bundle/logger-bundle.module.js +22 -0
- package/dist/lib/bundle/logger-bundle.module.js.map +1 -0
- package/dist/lib/bundle/logger-bundle.service.d.ts +41 -0
- package/dist/lib/bundle/logger-bundle.service.js +107 -0
- package/dist/lib/bundle/logger-bundle.service.js.map +1 -0
- package/dist/lib/core/filters/logger-exception.filter.d.ts +10 -0
- package/dist/lib/core/filters/logger-exception.filter.js +48 -0
- package/dist/lib/core/filters/logger-exception.filter.js.map +1 -0
- package/dist/lib/core/filters/logger-http.interceptor.d.ts +9 -0
- package/dist/lib/core/filters/logger-http.interceptor.js +57 -0
- package/dist/lib/core/filters/logger-http.interceptor.js.map +1 -0
- package/dist/lib/core/index.d.ts +4 -0
- package/dist/lib/core/index.js +21 -0
- package/dist/lib/core/index.js.map +1 -0
- package/dist/lib/core/middleware/bind-logger.middleware.d.ts +8 -0
- package/dist/lib/core/middleware/bind-logger.middleware.js +32 -0
- package/dist/lib/core/middleware/bind-logger.middleware.js.map +1 -0
- package/dist/lib/core/providers/pino-logger.provider.d.ts +2 -0
- package/dist/lib/core/providers/pino-logger.provider.js +56 -0
- package/dist/lib/core/providers/pino-logger.provider.js.map +1 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +23 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/logger/index.d.ts +2 -0
- package/dist/lib/logger/index.js +19 -0
- package/dist/lib/logger/index.js.map +1 -0
- package/dist/lib/logger/internal-logger.service.d.ts +22 -0
- package/dist/lib/logger/internal-logger.service.js +77 -0
- package/dist/lib/logger/internal-logger.service.js.map +1 -0
- package/dist/lib/logger/logger.service.d.ts +36 -0
- package/dist/lib/logger/logger.service.js +118 -0
- package/dist/lib/logger/logger.service.js.map +1 -0
- package/dist/lib/nest-logger.module-definition.d.ts +6 -0
- package/dist/lib/nest-logger.module-definition.js +16 -0
- package/dist/lib/nest-logger.module-definition.js.map +1 -0
- package/dist/lib/nest-logger.module.d.ts +10 -0
- package/dist/lib/nest-logger.module.js +66 -0
- package/dist/lib/nest-logger.module.js.map +1 -0
- package/dist/lib/nest-logger.params.d.ts +58 -0
- package/dist/lib/nest-logger.params.js +23 -0
- package/dist/lib/nest-logger.params.js.map +1 -0
- package/dist/lib/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
import { Logger } from 'pino';
|
|
4
|
+
export declare class NestLoggerStore {
|
|
5
|
+
loggerContext: any;
|
|
6
|
+
reqId: any;
|
|
7
|
+
logger: Logger;
|
|
8
|
+
constructor(loggerContext: any, reqId: any, logger: Logger);
|
|
9
|
+
}
|
|
10
|
+
export declare const NestLoggerStorage: AsyncLocalStorage<NestLoggerStore>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestLoggerStorage = exports.NestLoggerStore = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
class NestLoggerStore {
|
|
6
|
+
constructor(loggerContext, reqId, logger) {
|
|
7
|
+
this.loggerContext = loggerContext;
|
|
8
|
+
this.reqId = reqId;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.NestLoggerStore = NestLoggerStore;
|
|
13
|
+
exports.NestLoggerStorage = new async_hooks_1.AsyncLocalStorage();
|
|
14
|
+
//# sourceMappingURL=async-logger.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-logger.hook.js","sourceRoot":"","sources":["../../../../lib/src/bundle/context/async-logger.hook.ts"],"names":[],"mappings":";;;AACA,6CAAgD;AAGhD,MAAa,eAAe;IAC3B,YAAmB,aAAkB,EAAS,KAAU,EAAS,MAAc;QAA5D,kBAAa,GAAb,aAAa,CAAK;QAAS,UAAK,GAAL,KAAK,CAAK;QAAS,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;CACnF;AAFD,0CAEC;AAEY,QAAA,iBAAiB,GAAG,IAAI,+BAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
export declare type PinoLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
3
|
+
export declare type PinoMethods = Pick<pino.Logger, PinoLevels>;
|
|
4
|
+
export declare type LoggerFunction = ((msg: string, ...args: any[]) => void) | ((obj: object, msg?: string, ...args: any[]) => void);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.definitions.js","sourceRoot":"","sources":["../../../../lib/src/bundle/context/logger.definitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PinoMethods } from './context/logger.definitions';
|
|
2
|
+
export declare class DummyLogger implements PinoMethods {
|
|
3
|
+
setContextToken(_: string): void;
|
|
4
|
+
enter(_: string): void;
|
|
5
|
+
trace(msg: string, ...args: any[]): void;
|
|
6
|
+
trace(obj: unknown, msg?: string, ...args: any[]): void;
|
|
7
|
+
debug(msg: string, ...args: any[]): void;
|
|
8
|
+
debug(obj: unknown, msg?: string, ...args: any[]): void;
|
|
9
|
+
info(msg: string, ...args: any[]): void;
|
|
10
|
+
info(obj: unknown, msg?: string, ...args: any[]): void;
|
|
11
|
+
warn(msg: string, ...args: any[]): void;
|
|
12
|
+
warn(obj: unknown, msg?: string, ...args: any[]): void;
|
|
13
|
+
error(msg: string, ...args: any[]): void;
|
|
14
|
+
error(obj: unknown, msg?: string, ...args: any[]): void;
|
|
15
|
+
fatal(msg: string, ...args: any[]): void;
|
|
16
|
+
fatal(obj: unknown, msg?: string, ...args: any[]): void;
|
|
17
|
+
exit(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DummyLogger = void 0;
|
|
4
|
+
class DummyLogger {
|
|
5
|
+
setContextToken(_) { }
|
|
6
|
+
enter(_) { }
|
|
7
|
+
trace(..._) { }
|
|
8
|
+
debug(..._) { }
|
|
9
|
+
info(..._) { }
|
|
10
|
+
warn(..._) { }
|
|
11
|
+
error(..._) { }
|
|
12
|
+
fatal(..._) { }
|
|
13
|
+
exit() { }
|
|
14
|
+
}
|
|
15
|
+
exports.DummyLogger = DummyLogger;
|
|
16
|
+
//# sourceMappingURL=dummy-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy-logger.js","sourceRoot":"","sources":["../../../lib/src/bundle/dummy-logger.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IACvB,eAAe,CAAC,CAAS,IAAG,CAAC;IAE7B,KAAK,CAAC,CAAS,IAAG,CAAC;IAInB,KAAK,CAAC,GAAG,CAA6B,IAAG,CAAC;IAI1C,KAAK,CAAC,GAAG,CAA6B,IAAG,CAAC;IAI1C,IAAI,CAAC,GAAG,CAA6B,IAAG,CAAC;IAIzC,IAAI,CAAC,GAAG,CAA6B,IAAG,CAAC;IAIzC,KAAK,CAAC,GAAG,CAA6B,IAAG,CAAC;IAI1C,KAAK,CAAC,GAAG,CAA6B,IAAG,CAAC;IAE1C,IAAI,KAAI,CAAC;CACT;AA9BD,kCA8BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './context/async-logger-context.service';
|
|
2
|
+
export * from './context/async-logger.hook';
|
|
3
|
+
export * from './context/logger.definitions';
|
|
4
|
+
export * from './logger-branch/branch.utils';
|
|
5
|
+
export * from './logger-branch/logger-branch';
|
|
6
|
+
export * from './logger-branch/logger-leaf';
|
|
7
|
+
export * from './logger-branch/logger-node';
|
|
8
|
+
export * from './dummy-logger';
|
|
9
|
+
export * from './logger-bundle.module';
|
|
10
|
+
export * from './logger-bundle.service';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context/async-logger-context.service"), exports);
|
|
18
|
+
__exportStar(require("./context/async-logger.hook"), exports);
|
|
19
|
+
__exportStar(require("./context/logger.definitions"), exports);
|
|
20
|
+
__exportStar(require("./logger-branch/branch.utils"), exports);
|
|
21
|
+
__exportStar(require("./logger-branch/logger-branch"), exports);
|
|
22
|
+
__exportStar(require("./logger-branch/logger-leaf"), exports);
|
|
23
|
+
__exportStar(require("./logger-branch/logger-node"), exports);
|
|
24
|
+
__exportStar(require("./dummy-logger"), exports);
|
|
25
|
+
__exportStar(require("./logger-bundle.module"), exports);
|
|
26
|
+
__exportStar(require("./logger-bundle.service"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/src/bundle/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yEAAuD;AACvD,8DAA4C;AAC5C,+DAA6C;AAE7C,+DAA6C;AAC7C,gEAA8C;AAC9C,8DAA4C;AAC5C,8DAA4C;AAE5C,iDAA+B;AAC/B,yDAAuC;AACvC,0DAAwC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoggerFunction } from '../context/logger.definitions';
|
|
2
|
+
export declare class LoggerBranchUtils {
|
|
3
|
+
private constructor();
|
|
4
|
+
static parseLoggedParamsToObject(log: Parameters<LoggerFunction>): ({
|
|
5
|
+
message: any;
|
|
6
|
+
} & object) | {
|
|
7
|
+
message: any;
|
|
8
|
+
error: Error;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LoggerBranchUtils = void 0;
|
|
7
|
+
const quick_format_unescaped_1 = __importDefault(require("quick-format-unescaped"));
|
|
8
|
+
class LoggerBranchUtils {
|
|
9
|
+
constructor() { }
|
|
10
|
+
static parseLoggedParamsToObject(log) {
|
|
11
|
+
if (typeof log[0] === 'object') {
|
|
12
|
+
if (log[0] instanceof Error) {
|
|
13
|
+
return {
|
|
14
|
+
message: (0, quick_format_unescaped_1.default)(log[1], log.slice(2)),
|
|
15
|
+
error: log[0],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return Object.assign({
|
|
20
|
+
message: (0, quick_format_unescaped_1.default)(log[1], log.slice(2)),
|
|
21
|
+
}, log[0]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return {
|
|
26
|
+
message: (0, quick_format_unescaped_1.default)(log[0], log.slice(1)),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.LoggerBranchUtils = LoggerBranchUtils;
|
|
32
|
+
//# sourceMappingURL=branch.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch.utils.js","sourceRoot":"","sources":["../../../../lib/src/bundle/logger-branch/branch.utils.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA4C;AAG5C,MAAa,iBAAiB;IAC7B,gBAAuB,CAAC;IAExB,MAAM,CAAC,yBAAyB,CAAC,GAA+B;QAC/D,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;YAC/B,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,KAAK,EAAE;gBAC5B,OAAO;oBACN,OAAO,EAAE,IAAA,gCAAM,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACrC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;iBACb,CAAC;aACF;iBAAM;gBACN,OAAO,MAAM,CAAC,MAAM,CACnB;oBACC,OAAO,EAAE,IAAA,gCAAM,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBACrC,EACD,GAAG,CAAC,CAAC,CAAC,CACN,CAAC;aACF;SACD;aAAM;YACN,OAAO;gBACN,OAAO,EAAE,IAAA,gCAAM,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACrC,CAAC;SACF;IACF,CAAC;CACD;AAxBD,8CAwBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import pino from "pino";
|
|
2
|
+
import { LoggerFunction, PinoLevels } from "../context/logger.definitions";
|
|
3
|
+
import { LoggerNode } from "./logger-node";
|
|
4
|
+
import { NestLoggerLevelStrategy } from '../../nest-logger.params';
|
|
5
|
+
export declare class LoggerBranch implements LoggerNode {
|
|
6
|
+
private _parent;
|
|
7
|
+
branchName: string;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
exitedAt?: number;
|
|
10
|
+
branchs: LoggerNode[];
|
|
11
|
+
constructor(_parent: LoggerBranch, branchName: string);
|
|
12
|
+
get parent(): LoggerBranch;
|
|
13
|
+
enter(branchName: string): LoggerBranch;
|
|
14
|
+
log(level: pino.Level, ...params: Parameters<LoggerFunction>): void;
|
|
15
|
+
exit(): LoggerBranch;
|
|
16
|
+
profiling(): number;
|
|
17
|
+
introspectLevel(strategy?: NestLoggerLevelStrategy, defaultLevel?: PinoLevels): PinoLevels;
|
|
18
|
+
toObject(): {
|
|
19
|
+
profiling: string;
|
|
20
|
+
name: string;
|
|
21
|
+
logs: any[];
|
|
22
|
+
};
|
|
23
|
+
clone(parent?: LoggerBranch): LoggerBranch;
|
|
24
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LoggerBranch = void 0;
|
|
7
|
+
const pino_1 = __importDefault(require("pino"));
|
|
8
|
+
const logger_leaf_1 = require("./logger-leaf");
|
|
9
|
+
const nest_logger_params_1 = require("../../nest-logger.params");
|
|
10
|
+
class LoggerBranch {
|
|
11
|
+
constructor(_parent, branchName) {
|
|
12
|
+
this._parent = _parent;
|
|
13
|
+
this.branchName = branchName;
|
|
14
|
+
this.createdAt = Date.now();
|
|
15
|
+
this.exitedAt = null;
|
|
16
|
+
this.branchs = [];
|
|
17
|
+
}
|
|
18
|
+
get parent() {
|
|
19
|
+
return this._parent;
|
|
20
|
+
}
|
|
21
|
+
enter(branchName) {
|
|
22
|
+
const newBranch = new LoggerBranch(this, branchName);
|
|
23
|
+
this.branchs.push(newBranch);
|
|
24
|
+
return newBranch;
|
|
25
|
+
}
|
|
26
|
+
log(level, ...params) {
|
|
27
|
+
this.branchs.push(new logger_leaf_1.LoggerLeaf(level, params));
|
|
28
|
+
}
|
|
29
|
+
exit() {
|
|
30
|
+
this.exitedAt = Date.now();
|
|
31
|
+
if (this._parent)
|
|
32
|
+
return this.parent;
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
profiling() {
|
|
36
|
+
if (this.exitedAt === null || this.exitedAt === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
return this.exitedAt - this.createdAt;
|
|
39
|
+
}
|
|
40
|
+
introspectLevel(strategy = nest_logger_params_1.NestLoggerLevelStrategy.MAJOR_LEVEL, defaultLevel = 'info') {
|
|
41
|
+
let currentLevel = null;
|
|
42
|
+
for (const branch of this.branchs) {
|
|
43
|
+
const cLevel = branch.introspectLevel(strategy, defaultLevel);
|
|
44
|
+
if (currentLevel === null) {
|
|
45
|
+
currentLevel = cLevel;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const lv1 = pino_1.default.levels.values[currentLevel];
|
|
49
|
+
const lv2 = pino_1.default.levels.values[cLevel];
|
|
50
|
+
switch (strategy) {
|
|
51
|
+
default:
|
|
52
|
+
case nest_logger_params_1.NestLoggerLevelStrategy.LAST_LEVEL:
|
|
53
|
+
currentLevel = cLevel;
|
|
54
|
+
break;
|
|
55
|
+
case nest_logger_params_1.NestLoggerLevelStrategy.MINOR_LEVEL: {
|
|
56
|
+
currentLevel = pino_1.default.levels.labels[Math.min(lv1, lv2)];
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case nest_logger_params_1.NestLoggerLevelStrategy.MAJOR_LEVEL:
|
|
60
|
+
currentLevel = pino_1.default.levels.labels[Math.max(lv1, lv2)];
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (currentLevel === null)
|
|
66
|
+
currentLevel = defaultLevel;
|
|
67
|
+
return currentLevel;
|
|
68
|
+
}
|
|
69
|
+
toObject() {
|
|
70
|
+
const object = {
|
|
71
|
+
profiling: this.exitedAt - this.createdAt + 'ms',
|
|
72
|
+
name: this.branchName,
|
|
73
|
+
logs: [],
|
|
74
|
+
};
|
|
75
|
+
for (let branch of this.branchs) {
|
|
76
|
+
object.logs.push(branch.toObject());
|
|
77
|
+
}
|
|
78
|
+
return object;
|
|
79
|
+
}
|
|
80
|
+
clone(parent = null) {
|
|
81
|
+
const cloned = new LoggerBranch(parent, this.branchName);
|
|
82
|
+
cloned.createdAt = this.createdAt;
|
|
83
|
+
cloned.exitedAt = this.exitedAt;
|
|
84
|
+
for (let branch of this.branchs) {
|
|
85
|
+
cloned.branchs.push(branch.clone(cloned));
|
|
86
|
+
}
|
|
87
|
+
return cloned;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.LoggerBranch = LoggerBranch;
|
|
91
|
+
//# sourceMappingURL=logger-branch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-branch.js","sourceRoot":"","sources":["../../../../lib/src/bundle/logger-branch/logger-branch.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,+CAA2C;AAE3C,iEAAmE;AAEnE,MAAa,YAAY;IAMxB,YAAoB,OAAqB,EAAS,UAAkB;QAAhD,YAAO,GAAP,OAAO,CAAc;QAAS,eAAU,GAAV,UAAU,CAAQ;QALpE,cAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,aAAQ,GAAY,IAAI,CAAC;QAEzB,YAAO,GAAiB,EAAE,CAAC;IAE4C,CAAC;IAExE,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,UAAkB;QACvB,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,GAAG,CAAC,KAAiB,EAAE,GAAG,MAAkC;QAC3D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,wBAAU,CAAC,K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AG,cAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAe,CAAC;wBACpE,MAAM;iBACP;aACD;SACD;QACD,IAAI,YAAY,KAAK,IAAI;YAAE,YAAY,GAAG,YAAY,CAAC;QACvD,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,QAAQ;QACP,MAAM,MAAM,GAAG;YACd,SAAS,EAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI;YAChD,IAAI,EAAE,IAAI,CAAC,UAAU;YACrB,IAAI,EAAE,EAAE;SACR,CAAC;QACF,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;SACpC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAuB,IAAI;QAChC,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACzD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChC,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;SAC1C;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAnFD,oCAmFC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NestLoggerLevelStrategy } from "../../nest-logger.params";
|
|
2
|
+
import pino from "pino";
|
|
3
|
+
import { LoggerFunction, PinoLevels } from "../context/logger.definitions";
|
|
4
|
+
import { LoggerNode } from "./logger-node";
|
|
5
|
+
export declare class LoggerLeaf implements LoggerNode {
|
|
6
|
+
level: pino.Level;
|
|
7
|
+
log: Parameters<LoggerFunction>;
|
|
8
|
+
constructor(level: pino.Level, log: Parameters<LoggerFunction>);
|
|
9
|
+
toObject(): {
|
|
10
|
+
message: any;
|
|
11
|
+
level: pino.Level;
|
|
12
|
+
} | {
|
|
13
|
+
message: any;
|
|
14
|
+
error: Error;
|
|
15
|
+
level: pino.Level;
|
|
16
|
+
};
|
|
17
|
+
introspectLevel(_: NestLoggerLevelStrategy, defaultLevel?: PinoLevels): PinoLevels;
|
|
18
|
+
clone(): LoggerNode;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerLeaf = void 0;
|
|
4
|
+
const branch_utils_1 = require("./branch.utils");
|
|
5
|
+
class LoggerLeaf {
|
|
6
|
+
constructor(level, log) {
|
|
7
|
+
this.level = level;
|
|
8
|
+
this.log = log;
|
|
9
|
+
}
|
|
10
|
+
toObject() {
|
|
11
|
+
return {
|
|
12
|
+
level: this.level,
|
|
13
|
+
...branch_utils_1.LoggerBranchUtils.parseLoggedParamsToObject(this.log),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
introspectLevel(_, defaultLevel = 'info') {
|
|
17
|
+
if (!this.level)
|
|
18
|
+
return defaultLevel;
|
|
19
|
+
return this.level;
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
const clonedLoggedObject = JSON.parse(JSON.stringify(this.log));
|
|
23
|
+
return new LoggerLeaf(this.level, clonedLoggedObject);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.LoggerLeaf = LoggerLeaf;
|
|
27
|
+
//# sourceMappingURL=logger-leaf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-leaf.js","sourceRoot":"","sources":["../../../../lib/src/bundle/logger-branch/logger-leaf.ts"],"names":[],"mappings":";;;AAGA,iDAAmD;AAInD,MAAa,UAAU;IACtB,YAAmB,KAAiB,EAAS,GAA+B;QAAzD,UAAK,GAAL,KAAK,CAAY;QAAS,QAAG,GAAH,GAAG,CAA4B;IAAG,CAAC;IAEhF,QAAQ;QACP,OAAO;YACN,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,gCAAiB,CAAC,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC;SACxD,CAAC;IACH,CAAC;IAED,eAAe,CAAC,CAA0B,EAAE,eAA2B,MAAM;QAC5E,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO,YAAY,CAAC;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED,KAAK;QAEJ,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAChE,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACvD,CAAC;CACD;AApBD,gCAoBC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NestLoggerLevelStrategy } from "../../nest-logger.params";
|
|
2
|
+
import { PinoLevels } from "../context/logger.definitions";
|
|
3
|
+
export interface LoggerNode {
|
|
4
|
+
toObject(): any;
|
|
5
|
+
introspectLevel(_: NestLoggerLevelStrategy, defaultLevel: string): PinoLevels;
|
|
6
|
+
clone(parent?: LoggerNode): LoggerNode;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-node.js","sourceRoot":"","sources":["../../../../lib/src/bundle/logger-branch/logger-node.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NestLoggerBundleModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const async_logger_context_service_1 = require("./context/async-logger-context.service");
|
|
12
|
+
const logger_bundle_service_1 = require("./logger-bundle.service");
|
|
13
|
+
let NestLoggerBundleModule = class NestLoggerBundleModule {
|
|
14
|
+
};
|
|
15
|
+
NestLoggerBundleModule = __decorate([
|
|
16
|
+
(0, common_1.Module)({
|
|
17
|
+
providers: [async_logger_context_service_1.NestAsyncLoggerContext, logger_bundle_service_1.NestLoggerBundle],
|
|
18
|
+
exports: [async_logger_context_service_1.NestAsyncLoggerContext, logger_bundle_service_1.NestLoggerBundle],
|
|
19
|
+
})
|
|
20
|
+
], NestLoggerBundleModule);
|
|
21
|
+
exports.NestLoggerBundleModule = NestLoggerBundleModule;
|
|
22
|
+
//# sourceMappingURL=logger-bundle.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-bundle.module.js","sourceRoot":"","sources":["../../../lib/src/bundle/logger-bundle.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yFAAgF;AAChF,mEAA2D;AAM3D,IAAa,sBAAsB,GAAnC,MAAa,sBAAsB;CAAG,CAAA;AAAzB,sBAAsB;IAJlC,IAAA,eAAM,EAAC;QACP,SAAS,EAAE,CAAC,qDAAsB,EAAE,wCAAgB,CAAC;QACrD,OAAO,EAAE,CAAC,qDAAsB,EAAE,wCAAgB,CAAC;KACnD,CAAC;GACW,sBAAsB,CAAG;AAAzB,wDAAsB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NestLoggerParams } from '../nest-logger.params';
|
|
2
|
+
import pino from 'pino';
|
|
3
|
+
export interface LoggerBindingsContext {
|
|
4
|
+
method?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
duration?: number;
|
|
7
|
+
ip?: string;
|
|
8
|
+
response?: {
|
|
9
|
+
statusCode: number;
|
|
10
|
+
headers: any;
|
|
11
|
+
data?: any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface LoggerBindings {
|
|
15
|
+
context: LoggerBindingsContext;
|
|
16
|
+
tags: {
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class LoggableBundleObject {
|
|
21
|
+
object: any;
|
|
22
|
+
level: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class NestLoggerBundle {
|
|
25
|
+
private params;
|
|
26
|
+
private expired;
|
|
27
|
+
private currentBranch;
|
|
28
|
+
private bindings;
|
|
29
|
+
constructor(params: NestLoggerParams);
|
|
30
|
+
setContext(context: LoggerBindingsContext): void;
|
|
31
|
+
putTag(tag: string, value: string): void;
|
|
32
|
+
copyFrom(otherBundle: NestLoggerBundle): void;
|
|
33
|
+
enter(branchName: string): void;
|
|
34
|
+
log(level: pino.Level, msg: string, ...args: any[]): void;
|
|
35
|
+
log(level: pino.Level, obj: unknown, msg?: string, ...args: any[]): void;
|
|
36
|
+
exit(): void;
|
|
37
|
+
private getRootBranch;
|
|
38
|
+
build(): LoggableBundleObject;
|
|
39
|
+
expireNow(): void;
|
|
40
|
+
isExpired(): boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.NestLoggerBundle = exports.LoggableBundleObject = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const nest_logger_params_1 = require("../nest-logger.params");
|
|
18
|
+
const nest_logger_module_definition_1 = require("../nest-logger.module-definition");
|
|
19
|
+
const logger_branch_1 = require("./logger-branch/logger-branch");
|
|
20
|
+
class LoggableBundleObject {
|
|
21
|
+
}
|
|
22
|
+
exports.LoggableBundleObject = LoggableBundleObject;
|
|
23
|
+
let NestLoggerBundle = class NestLoggerBundle {
|
|
24
|
+
constructor(params) {
|
|
25
|
+
this.params = params;
|
|
26
|
+
this.expired = false;
|
|
27
|
+
this.currentBranch = new logger_branch_1.LoggerBranch(null, 'root');
|
|
28
|
+
this.bindings = {
|
|
29
|
+
context: {},
|
|
30
|
+
tags: {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
setContext(context) {
|
|
34
|
+
Object.assign(this.bindings.context, context);
|
|
35
|
+
}
|
|
36
|
+
putTag(tag, value) {
|
|
37
|
+
this.bindings.tags[tag] = value;
|
|
38
|
+
}
|
|
39
|
+
copyFrom(otherBundle) {
|
|
40
|
+
this.currentBranch = otherBundle.getRootBranch().clone();
|
|
41
|
+
this.bindings = {
|
|
42
|
+
context: Object.assign({}, otherBundle.bindings.context),
|
|
43
|
+
tags: Object.assign({}, otherBundle.bindings.tags),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
enter(branchName) {
|
|
47
|
+
this.currentBranch = this.currentBranch.enter(branchName);
|
|
48
|
+
}
|
|
49
|
+
log(level, ...params) {
|
|
50
|
+
this.currentBranch.log(level, ...params);
|
|
51
|
+
}
|
|
52
|
+
exit() {
|
|
53
|
+
if (!this.currentBranch.parent)
|
|
54
|
+
throw Error('Could not close current branch.');
|
|
55
|
+
this.currentBranch = this.currentBranch.exit();
|
|
56
|
+
}
|
|
57
|
+
getRootBranch() {
|
|
58
|
+
let current = this.currentBranch;
|
|
59
|
+
while (current.parent) {
|
|
60
|
+
current = current.parent;
|
|
61
|
+
}
|
|
62
|
+
return current;
|
|
63
|
+
}
|
|
64
|
+
build() {
|
|
65
|
+
var _a, _b, _c, _d, _e;
|
|
66
|
+
while (this.currentBranch.parent) {
|
|
67
|
+
this.currentBranch = this.currentBranch.exit();
|
|
68
|
+
}
|
|
69
|
+
this.currentBranch.exit();
|
|
70
|
+
const bindings = {
|
|
71
|
+
context: Object.assign({
|
|
72
|
+
requestDuration: this.currentBranch.profiling(),
|
|
73
|
+
}, this.bindings.context),
|
|
74
|
+
tags: Object.assign({}, this.bindings.tags),
|
|
75
|
+
};
|
|
76
|
+
delete bindings.context.response;
|
|
77
|
+
if (this.bindings.context.response) {
|
|
78
|
+
Object.assign(bindings, {
|
|
79
|
+
res: this.bindings.context.response,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const object = {
|
|
83
|
+
logs: this.currentBranch.toObject(),
|
|
84
|
+
...bindings,
|
|
85
|
+
};
|
|
86
|
+
const level = this.currentBranch.introspectLevel(((_c = (_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.contextBundle) === null || _b === void 0 ? void 0 : _b.strategy) === null || _c === void 0 ? void 0 : _c.level) || nest_logger_params_1.NestLoggerLevelStrategy.MAJOR_LEVEL, ((_e = (_d = this.params) === null || _d === void 0 ? void 0 : _d.contextBundle) === null || _e === void 0 ? void 0 : _e.defaultLevel) || 'info');
|
|
87
|
+
return {
|
|
88
|
+
object,
|
|
89
|
+
level,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
expireNow() {
|
|
93
|
+
this.expired = true;
|
|
94
|
+
}
|
|
95
|
+
isExpired() {
|
|
96
|
+
return this.expired;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
NestLoggerBundle = __decorate([
|
|
100
|
+
(0, common_1.Injectable)({
|
|
101
|
+
scope: common_1.Scope.REQUEST,
|
|
102
|
+
}),
|
|
103
|
+
__param(0, (0, common_1.Inject)(nest_logger_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
104
|
+
__metadata("design:paramtypes", [Object])
|
|
105
|
+
], NestLoggerBundle);
|
|
106
|
+
exports.NestLoggerBundle = NestLoggerBundle;
|
|
107
|
+
//# sourceMappingURL=logger-bundle.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-bundle.service.js","sourceRoot":"","sources":["../../../lib/src/bundle/logger-bundle.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,8DAAkF;AAElF,oFAAwE;AAExE,iEAA6D;AAsB7D,MAAa,oBAAoB;CAGhC;AAHD,oDAGC;AAQD,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAK5B,YAAkD,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QAJlE,YAAO,GAAY,KAAK,CAAC;QAKhC,IAAI,CAAC,aAAa,GAAG,IAAI,4BAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,GAAG;YACf,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,EAAE;SACR,CAAC;IACH,CAAC;IAED,UAAU,CAAC,OAA8B;QACxC,MAAM,CAAC,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U,EAAC;QACX,KAAK,EAAE,cAAK,CAAC,OAAO;KACpB,CAAC;IAMY,WAAA,IAAA,eAAM,EAAC,oDAAoB,CAAC,CAAA;;GAL7B,gBAAgB,CAsG5B;AAtGY,4CAAgB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import { BaseExceptionFilter } from '@nestjs/core';
|
|
3
|
+
import { NestAsyncLoggerContext } from '../../bundle/context/async-logger-context.service';
|
|
4
|
+
import { NestLoggerService } from '../../logger/logger.service';
|
|
5
|
+
export declare class LoggerExceptionFilter extends BaseExceptionFilter {
|
|
6
|
+
private loggerService;
|
|
7
|
+
private loggerContext;
|
|
8
|
+
constructor(loggerService: NestLoggerService, loggerContext: NestAsyncLoggerContext);
|
|
9
|
+
catch(exception: unknown, host: ArgumentsHost): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var LoggerExceptionFilter_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.LoggerExceptionFilter = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
16
|
+
const constants_1 = require("@nestjs/core/constants");
|
|
17
|
+
const async_logger_context_service_1 = require("../../bundle/context/async-logger-context.service");
|
|
18
|
+
const logger_service_1 = require("../../logger/logger.service");
|
|
19
|
+
let LoggerExceptionFilter = LoggerExceptionFilter_1 = class LoggerExceptionFilter extends core_1.BaseExceptionFilter {
|
|
20
|
+
constructor(loggerService, loggerContext) {
|
|
21
|
+
super();
|
|
22
|
+
this.loggerService = loggerService;
|
|
23
|
+
this.loggerContext = loggerContext;
|
|
24
|
+
this.loggerService.setContextToken(LoggerExceptionFilter_1.name);
|
|
25
|
+
}
|
|
26
|
+
catch(exception, host) {
|
|
27
|
+
const { httpAdapter } = this.httpAdapterHost;
|
|
28
|
+
const ctx = host.switchToHttp();
|
|
29
|
+
const status = exception instanceof common_1.HttpException ? exception.getStatus() : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
30
|
+
const message = exception instanceof common_1.HttpException ? exception.message : constants_1.MESSAGES.UNKNOWN_EXCEPTION_MESSAGE;
|
|
31
|
+
this.loggerService.error(exception, message);
|
|
32
|
+
if (this.loggerContext.hasContext())
|
|
33
|
+
this.loggerContext.dispatchCurrentLoggerBundle(exception, message);
|
|
34
|
+
const responseBody = {
|
|
35
|
+
statusCode: status,
|
|
36
|
+
message: message,
|
|
37
|
+
timestamp: new Date().toISOString(),
|
|
38
|
+
path: httpAdapter.getRequestUrl(ctx.getRequest()),
|
|
39
|
+
};
|
|
40
|
+
httpAdapter.reply(ctx.getResponse(), responseBody, status);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
LoggerExceptionFilter = LoggerExceptionFilter_1 = __decorate([
|
|
44
|
+
(0, common_1.Catch)(),
|
|
45
|
+
__metadata("design:paramtypes", [logger_service_1.NestLoggerService, async_logger_context_service_1.NestAsyncLoggerContext])
|
|
46
|
+
], LoggerExceptionFilter);
|
|
47
|
+
exports.LoggerExceptionFilter = LoggerExceptionFilter;
|
|
48
|
+
//# sourceMappingURL=logger-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-exception.filter.js","sourceRoot":"","sources":["../../../../lib/src/core/filters/logger-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKuB;AACvB,uCAAkD;AAClD,sDAAiD;AACjD,oGAA0F;AAC1F,gEAA+D;AAG/D,IAAa,qBAAqB,6BAAlC,MAAa,qBAAsB,SAAQ,0BAAmB;IAG7D,YAAoB,aAAgC,EAAU,aAAqC;QAClG,KAAK,EAAE,CAAA;QADY,kBAAa,GAAb,aAAa,CAAmB;QAAU,kBAAa,GAAb,aAAa,CAAwB;QAElG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,SAAkB,EAAE,IAAmB;QAE5C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,eAAe,CAAA;QAE5C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;QAE/B,MAAM,MAAM,GACX,SAAS,YAAY,sBAAa,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,mBAAU,CAAC,qBAAqB,CAAA;QAE9F,MAAM,OAAO,GACZ,SAAS,YAAY,sBAAa,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAQ,CAAC,yBAAyB,CAAA;QAE5F,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAG5C,IAAI,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,2BAA2B,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAGnE,MAAM,YAAY,GAAG;YACpB,UAAU,EAAE,MAAM;YAClB,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;SACjD,CAAA;QAED,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;CACD,CAAA;AApCY,qBAAqB;IADjC,IAAA,cAAK,GAAE;qCAI4B,kCAAiB,EAAyB,qDAAsB;GAHvF,qBAAqB,CAoCjC;AApCY,sDAAqB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { NestAsyncLoggerContext } from '../../bundle/context/async-logger-context.service';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
export declare class LoggerHttpInterceptor implements NestInterceptor {
|
|
5
|
+
private loggerContext;
|
|
6
|
+
constructor(loggerContext: NestAsyncLoggerContext);
|
|
7
|
+
private dispatchLogger;
|
|
8
|
+
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> | Promise<Observable<any>>;
|
|
9
|
+
}
|