@cryptexlabs/codex-nodejs-common 0.7.7 → 0.8.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/lib/package.json +1 -1
- package/lib/src/logger/context.logger.d.ts +5 -5
- package/lib/src/logger/context.logger.js +16 -12
- package/lib/src/logger/context.logger.js.map +1 -1
- package/lib/src/logger/custom.logger.d.ts +6 -6
- package/lib/src/logger/custom.logger.js +59 -21
- package/lib/src/logger/custom.logger.js.map +1 -1
- package/package.json +1 -1
- package/src/logger/context.logger.ts +20 -12
- package/src/logger/custom.logger.spec.ts +40 -11
- package/src/logger/custom.logger.ts +53 -25
package/lib/package.json
CHANGED
|
@@ -8,10 +8,10 @@ export declare class ContextLogger implements LoggerService {
|
|
|
8
8
|
private readonly logger;
|
|
9
9
|
private readonly stackTraceId;
|
|
10
10
|
constructor(correlationId: any, config: DefaultConfig, client: ClientInterface, logger: LoggerService);
|
|
11
|
-
debug(message: any,
|
|
12
|
-
error(message: any,
|
|
13
|
-
log(message: any,
|
|
14
|
-
verbose(message: any,
|
|
15
|
-
warn(message: any,
|
|
11
|
+
debug(message: any, ...optionalParams: any): any;
|
|
12
|
+
error(message: any, ...optionalParams: any): any;
|
|
13
|
+
log(message: any, ...optionalParams: any): any;
|
|
14
|
+
verbose(message: any, ...optionalParams: any): any;
|
|
15
|
+
warn(message: any, ...optionalParams: any): any;
|
|
16
16
|
private _getData;
|
|
17
17
|
}
|
|
@@ -10,23 +10,23 @@ class ContextLogger {
|
|
|
10
10
|
this.logger = logger;
|
|
11
11
|
this.stackTraceId = uuid_1.v4();
|
|
12
12
|
}
|
|
13
|
-
debug(message,
|
|
14
|
-
this.logger.debug(this._getData(message
|
|
13
|
+
debug(message, ...optionalParams) {
|
|
14
|
+
this.logger.debug(this._getData(message, optionalParams));
|
|
15
15
|
}
|
|
16
|
-
error(message,
|
|
17
|
-
this.logger.error(this._getData(message
|
|
16
|
+
error(message, ...optionalParams) {
|
|
17
|
+
this.logger.error(this._getData(message, optionalParams));
|
|
18
18
|
}
|
|
19
|
-
log(message,
|
|
20
|
-
this.logger.log(this._getData(message
|
|
19
|
+
log(message, ...optionalParams) {
|
|
20
|
+
this.logger.log(this._getData(message, optionalParams));
|
|
21
21
|
}
|
|
22
|
-
verbose(message,
|
|
23
|
-
this.logger.verbose(this._getData(message
|
|
22
|
+
verbose(message, ...optionalParams) {
|
|
23
|
+
this.logger.verbose(this._getData(message, optionalParams));
|
|
24
24
|
}
|
|
25
|
-
warn(message,
|
|
26
|
-
this.logger.warn(this._getData(message
|
|
25
|
+
warn(message, ...optionalParams) {
|
|
26
|
+
this.logger.warn(this._getData(message, optionalParams));
|
|
27
27
|
}
|
|
28
|
-
_getData(message) {
|
|
29
|
-
|
|
28
|
+
_getData(message, ...optionalParams) {
|
|
29
|
+
let logData = {
|
|
30
30
|
stackTraceId: this.stackTraceId,
|
|
31
31
|
correlationId: this.correlationId,
|
|
32
32
|
appVersion: this.config.appVersion,
|
|
@@ -36,6 +36,10 @@ class ContextLogger {
|
|
|
36
36
|
clientVariant: this.client.variant,
|
|
37
37
|
message,
|
|
38
38
|
};
|
|
39
|
+
if (optionalParams) {
|
|
40
|
+
logData = Object.assign(Object.assign({}, logData), { data: Object.assign({}, optionalParams) });
|
|
41
|
+
}
|
|
42
|
+
return logData;
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
exports.ContextLogger = ContextLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.logger.js","sourceRoot":"","sources":["../../../src/logger/context.logger.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAIpC,MAAa,aAAa;IAGxB,YACmB,aAAa,EACb,MAAqB,EACrB,MAAuB,EACvB,MAAqB;QAHrB,kBAAa,GAAb,aAAa,CAAA;QACb,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAiB;QACvB,WAAM,GAAN,MAAM,CAAe;QAEtC,IAAI,CAAC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D,CAAC;IAEO,QAAQ,CAAC,OAAO,EAAE,GAAG,cAAc;QACzC,IAAI,OAAO,GAAQ;YACjB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YAC5B,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAClC,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAClC,OAAO;SACR,CAAC;QAEF,IAAI,cAAc,EAAE;YAClB,OAAO,mCACF,OAAO,KACV,IAAI,oBAAO,cAAc,IAC1B,CAAC;SACH;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AApDD,sCAoDC"}
|
|
@@ -4,10 +4,10 @@ export declare class CustomLogger implements LoggerService {
|
|
|
4
4
|
private readonly logger;
|
|
5
5
|
private readonly filterContext;
|
|
6
6
|
constructor(defaultContext?: string, filterContext?: string[], isTimestampEnabled?: boolean, logger?: LoggerService);
|
|
7
|
-
log(message: string,
|
|
8
|
-
error(error: string | Error,
|
|
9
|
-
debug(message: any,
|
|
10
|
-
verbose(message: any,
|
|
11
|
-
warn(message: any,
|
|
12
|
-
info(message: any
|
|
7
|
+
log(message: string, ...optionalParams: any): void;
|
|
8
|
+
error(error: string | Error, ...optionalParams: any): void;
|
|
9
|
+
debug(message: any, ...optionalParams: any): void;
|
|
10
|
+
verbose(message: any, ...optionalParams: any): any;
|
|
11
|
+
warn(message: any, ...optionalParams: any): any;
|
|
12
|
+
info(message: any): any;
|
|
13
13
|
}
|
|
@@ -24,29 +24,26 @@ let CustomLogger = class CustomLogger {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
log(message,
|
|
28
|
-
if (context === "") {
|
|
29
|
-
context = this.defaultContext;
|
|
30
|
-
}
|
|
27
|
+
log(message, ...optionalParams) {
|
|
31
28
|
if (this.filterContext.length > 0) {
|
|
32
|
-
if (this.filterContext.includes(
|
|
33
|
-
this.logger.log(message,
|
|
29
|
+
if (this.filterContext.includes("log")) {
|
|
30
|
+
this.logger.log(message, ...optionalParams);
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
|
-
this.logger.log(message,
|
|
34
|
+
this.logger.log(message, ...optionalParams);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
error(error,
|
|
37
|
+
error(error, ...optionalParams) {
|
|
41
38
|
let message;
|
|
42
39
|
let useTrace;
|
|
43
40
|
if (error instanceof Error) {
|
|
44
41
|
message = error.message;
|
|
45
42
|
useTrace = error.stack;
|
|
46
43
|
}
|
|
47
|
-
else {
|
|
44
|
+
else if (typeof error === "object" && error.stack) {
|
|
48
45
|
message = error;
|
|
49
|
-
useTrace =
|
|
46
|
+
useTrace = error.stack;
|
|
50
47
|
}
|
|
51
48
|
if (!message && error.message) {
|
|
52
49
|
message = error.message;
|
|
@@ -54,26 +51,67 @@ let CustomLogger = class CustomLogger {
|
|
|
54
51
|
if (!useTrace && error.stack) {
|
|
55
52
|
useTrace = error.stack;
|
|
56
53
|
}
|
|
54
|
+
if (!message && typeof error === "string") {
|
|
55
|
+
message = error;
|
|
56
|
+
}
|
|
57
57
|
if (this.filterContext.length > 0) {
|
|
58
|
-
if (this.filterContext.includes(
|
|
59
|
-
|
|
58
|
+
if (this.filterContext.includes("error")) {
|
|
59
|
+
if (useTrace) {
|
|
60
|
+
this.logger.error(message, Object.assign({ trace: useTrace }, optionalParams));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.logger.error(message, ...optionalParams);
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
else {
|
|
63
|
-
|
|
68
|
+
if (useTrace) {
|
|
69
|
+
this.logger.error(message, Object.assign({ trace: useTrace }, optionalParams));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.logger.error(message, ...optionalParams);
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
|
-
debug(message,
|
|
67
|
-
this.
|
|
76
|
+
debug(message, ...optionalParams) {
|
|
77
|
+
if (this.filterContext.length > 0) {
|
|
78
|
+
if (this.filterContext.includes("debug")) {
|
|
79
|
+
this.logger.debug(message, ...optionalParams);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.logger.debug(message, ...optionalParams);
|
|
84
|
+
}
|
|
68
85
|
}
|
|
69
|
-
verbose(message,
|
|
70
|
-
this.
|
|
86
|
+
verbose(message, ...optionalParams) {
|
|
87
|
+
if (this.filterContext.length > 0) {
|
|
88
|
+
if (this.filterContext.includes("verbose")) {
|
|
89
|
+
this.logger.verbose(message, ...optionalParams);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.logger.verbose(message, ...optionalParams);
|
|
94
|
+
}
|
|
71
95
|
}
|
|
72
|
-
warn(message,
|
|
73
|
-
this.
|
|
96
|
+
warn(message, ...optionalParams) {
|
|
97
|
+
if (this.filterContext.length > 0) {
|
|
98
|
+
if (this.filterContext.includes("warn")) {
|
|
99
|
+
this.logger.warn(message, ...optionalParams);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.logger.warn(message, ...optionalParams);
|
|
104
|
+
}
|
|
74
105
|
}
|
|
75
|
-
info(message
|
|
76
|
-
this.
|
|
106
|
+
info(message) {
|
|
107
|
+
if (this.filterContext.length > 0) {
|
|
108
|
+
if (this.filterContext.includes("info")) {
|
|
109
|
+
this.logger.log(message, "info");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.logger.log(message, "info");
|
|
114
|
+
}
|
|
77
115
|
}
|
|
78
116
|
};
|
|
79
117
|
CustomLogger = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.logger.js","sourceRoot":"","sources":["../../../src/logger/custom.logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmE;AAGnE,IAAa,YAAY,GAAzB,MAAa,YAAY;IAIvB,YACU,iBAAyB,MAAM,EACvC,gBAA0B,EAAE,EAC5B,kBAA4B,EAC5B,MAAsB;QAHd,mBAAc,GAAd,cAAc,CAAiB;QAKvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,cAAc,EAAE;gBACvC,SAAS,EAAE,kBAAkB;aAC9B,CAAC,CAAC;SACJ;IACH,CAAC;IAEM,GAAG,CAAC,OAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"custom.logger.js","sourceRoot":"","sources":["../../../src/logger/custom.logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmE;AAGnE,IAAa,YAAY,GAAzB,MAAa,YAAY;IAIvB,YACU,iBAAyB,MAAM,EACvC,gBAA0B,EAAE,EAC5B,kBAA4B,EAC5B,MAAsB;QAHd,mBAAc,GAAd,cAAc,CAAiB;QAKvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,cAAc,EAAE;gBACvC,SAAS,EAAE,kBAAkB;aAC9B,CAAC,CAAC;SACJ;IACH,CAAC;IAEM,GAAG,CAAC,OAAe,EAAE,GAAG,cAAmB;QAChD,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YACjC,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACtC,IAAI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AI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;SAC9C;IACH,CAAC;IAEM,IAAI,CAAC,OAAY;QACtB,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YACjC,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;aAClC;SACF;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAClC;IACH,CAAC;CACF,CAAA;AA3GY,YAAY;IADxB,mBAAU,EAAE;;GACA,YAAY,CA2GxB;AA3GY,oCAAY"}
|
package/package.json
CHANGED
|
@@ -15,28 +15,28 @@ export class ContextLogger implements LoggerService {
|
|
|
15
15
|
this.stackTraceId = uuidV4();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
public debug(message: any,
|
|
19
|
-
this.logger.debug(this._getData(message
|
|
18
|
+
public debug(message: any, ...optionalParams: any): any {
|
|
19
|
+
this.logger.debug(this._getData(message, optionalParams));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public error(message: any,
|
|
23
|
-
this.logger.error(this._getData(message
|
|
22
|
+
public error(message: any, ...optionalParams: any): any {
|
|
23
|
+
this.logger.error(this._getData(message, optionalParams));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public log(message: any,
|
|
27
|
-
this.logger.log(this._getData(message
|
|
26
|
+
public log(message: any, ...optionalParams: any): any {
|
|
27
|
+
this.logger.log(this._getData(message, optionalParams));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public verbose(message: any,
|
|
31
|
-
this.logger.verbose(this._getData(message
|
|
30
|
+
public verbose(message: any, ...optionalParams: any): any {
|
|
31
|
+
this.logger.verbose(this._getData(message, optionalParams));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
public warn(message: any,
|
|
35
|
-
this.logger.warn(this._getData(message
|
|
34
|
+
public warn(message: any, ...optionalParams: any): any {
|
|
35
|
+
this.logger.warn(this._getData(message, optionalParams));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
private _getData(message) {
|
|
39
|
-
|
|
38
|
+
private _getData(message, ...optionalParams) {
|
|
39
|
+
let logData: any = {
|
|
40
40
|
stackTraceId: this.stackTraceId,
|
|
41
41
|
correlationId: this.correlationId,
|
|
42
42
|
appVersion: this.config.appVersion,
|
|
@@ -46,5 +46,13 @@ export class ContextLogger implements LoggerService {
|
|
|
46
46
|
clientVariant: this.client.variant,
|
|
47
47
|
message,
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
if (optionalParams) {
|
|
51
|
+
logData = {
|
|
52
|
+
...logData,
|
|
53
|
+
data: { ...optionalParams },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return logData;
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomLogger } from "./custom.logger";
|
|
2
2
|
import { Logger } from "@nestjs/common";
|
|
3
|
-
import { instance, mock, verify } from "ts-mockito";
|
|
3
|
+
import { deepEqual, instance, mock, verify } from "ts-mockito";
|
|
4
4
|
|
|
5
5
|
describe("CustomLogger", () => {
|
|
6
6
|
let loggerMock: Logger;
|
|
@@ -17,13 +17,13 @@ describe("CustomLogger", () => {
|
|
|
17
17
|
|
|
18
18
|
it("Should allow the default context when no filtered contexts are provided", () => {
|
|
19
19
|
const customLogger = new CustomLogger("info", [], true, loggerMock);
|
|
20
|
-
customLogger.
|
|
20
|
+
customLogger.info("hello");
|
|
21
21
|
verify(mockedLogger.log("hello", "info")).once();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it("Should allow the default context allowed filtered contexts is provided", () => {
|
|
25
25
|
const customLogger = new CustomLogger("info", ["info"], true, loggerMock);
|
|
26
|
-
customLogger.
|
|
26
|
+
customLogger.info("hello");
|
|
27
27
|
verify(mockedLogger.log("hello", "info")).once();
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -36,19 +36,19 @@ describe("CustomLogger", () => {
|
|
|
36
36
|
it("Should not allow custom context when filtered contexts does not include custom context", () => {
|
|
37
37
|
const customLogger = new CustomLogger("info", ["debug"], true, loggerMock);
|
|
38
38
|
customLogger.log("hello", "error");
|
|
39
|
-
verify(mockedLogger.
|
|
39
|
+
verify(mockedLogger.error("hello")).never();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
it("Should not allow error with a method when filtered contexts does not include error", () => {
|
|
43
43
|
const customLogger = new CustomLogger("info", ["debug"], true, loggerMock);
|
|
44
44
|
customLogger.error("hello", "", "");
|
|
45
|
-
verify(mockedLogger.error("hello", ""
|
|
45
|
+
verify(mockedLogger.error("hello", "")).never();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it("Should not allow debug with a method when filtered contexts does not include debug", () => {
|
|
49
49
|
const customLogger = new CustomLogger("info", ["info"], true, loggerMock);
|
|
50
50
|
customLogger.debug("hello");
|
|
51
|
-
verify(mockedLogger.
|
|
51
|
+
verify(mockedLogger.debug("hello")).never();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it("Should not allow info with a method when filtered contexts does not include info", () => {
|
|
@@ -60,13 +60,13 @@ describe("CustomLogger", () => {
|
|
|
60
60
|
it("Should not allow verbose with a method when filtered contexts does not include verbose", () => {
|
|
61
61
|
const customLogger = new CustomLogger("info", ["info"], true, loggerMock);
|
|
62
62
|
customLogger.verbose("hello");
|
|
63
|
-
verify(mockedLogger.
|
|
63
|
+
verify(mockedLogger.verbose("hello")).never();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it("Should not allow warn with a method when filtered contexts does not include warn", () => {
|
|
67
67
|
const customLogger = new CustomLogger("info", ["info"], true, loggerMock);
|
|
68
68
|
customLogger.warn("hello");
|
|
69
|
-
verify(mockedLogger.
|
|
69
|
+
verify(mockedLogger.warn("hello")).never();
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it("Should allow debug with a method when filtered contexts does not include debug", () => {
|
|
@@ -77,12 +77,41 @@ describe("CustomLogger", () => {
|
|
|
77
77
|
loggerMock
|
|
78
78
|
);
|
|
79
79
|
customLogger.debug("hello");
|
|
80
|
-
verify(mockedLogger.
|
|
80
|
+
verify(mockedLogger.debug("hello")).once();
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
it("Should allow error when error is in filtered context", () => {
|
|
84
84
|
const customLogger = new CustomLogger("info", ["error"], true, loggerMock);
|
|
85
|
-
customLogger.error("hello"
|
|
86
|
-
verify(mockedLogger.error("hello"
|
|
85
|
+
customLogger.error("hello");
|
|
86
|
+
verify(mockedLogger.error("hello")).once();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("Should send custom options with debug level", () => {
|
|
90
|
+
const customLogger = new CustomLogger("info", ["debug"], true, loggerMock);
|
|
91
|
+
customLogger.debug("hello", { world: "gone" });
|
|
92
|
+
verify(mockedLogger.debug("hello", deepEqual({ world: "gone" }))).once();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("Should send custom options with error level", () => {
|
|
96
|
+
const customLogger = new CustomLogger("info", ["error"], true, loggerMock);
|
|
97
|
+
customLogger.error("hello", { world: "gone" });
|
|
98
|
+
verify(mockedLogger.error("hello", deepEqual({ world: "gone" }))).once();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("Should send custom options with verbose level", () => {
|
|
102
|
+
const customLogger = new CustomLogger(
|
|
103
|
+
"info",
|
|
104
|
+
["verbose"],
|
|
105
|
+
true,
|
|
106
|
+
loggerMock
|
|
107
|
+
);
|
|
108
|
+
customLogger.verbose("hello", { world: "gone" });
|
|
109
|
+
verify(mockedLogger.verbose("hello", deepEqual({ world: "gone" }))).once();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("Should send custom options with warn level", () => {
|
|
113
|
+
const customLogger = new CustomLogger("info", ["warn"], true, loggerMock);
|
|
114
|
+
customLogger.warn("hello", { world: "gone" });
|
|
115
|
+
verify(mockedLogger.warn("hello", deepEqual({ world: "gone" }))).once();
|
|
87
116
|
});
|
|
88
117
|
});
|
|
@@ -22,32 +22,25 @@ export class CustomLogger implements LoggerService {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public log(message: string,
|
|
26
|
-
if (context === "") {
|
|
27
|
-
context = this.defaultContext;
|
|
28
|
-
}
|
|
25
|
+
public log(message: string, ...optionalParams: any) {
|
|
29
26
|
if (this.filterContext.length > 0) {
|
|
30
|
-
if (this.filterContext.includes(
|
|
31
|
-
this.logger.log(message,
|
|
27
|
+
if (this.filterContext.includes("log")) {
|
|
28
|
+
this.logger.log(message, ...optionalParams);
|
|
32
29
|
}
|
|
33
30
|
} else {
|
|
34
|
-
this.logger.log(message,
|
|
31
|
+
this.logger.log(message, ...optionalParams);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
public error(
|
|
39
|
-
error: string | Error,
|
|
40
|
-
trace: string,
|
|
41
|
-
context: string = "error"
|
|
42
|
-
) {
|
|
35
|
+
public error(error: string | Error, ...optionalParams: any) {
|
|
43
36
|
let message;
|
|
44
37
|
let useTrace;
|
|
45
38
|
if (error instanceof Error) {
|
|
46
39
|
message = error.message;
|
|
47
40
|
useTrace = error.stack;
|
|
48
|
-
} else {
|
|
41
|
+
} else if (typeof error === "object" && (error as any).stack) {
|
|
49
42
|
message = error;
|
|
50
|
-
useTrace =
|
|
43
|
+
useTrace = (error as any).stack;
|
|
51
44
|
}
|
|
52
45
|
if (!message && ((error as any).message as any)) {
|
|
53
46
|
message = (error as any).message;
|
|
@@ -55,29 +48,64 @@ export class CustomLogger implements LoggerService {
|
|
|
55
48
|
if (!useTrace && ((error as any).stack as any)) {
|
|
56
49
|
useTrace = (error as any).stack;
|
|
57
50
|
}
|
|
51
|
+
if (!message && typeof error === "string") {
|
|
52
|
+
message = error;
|
|
53
|
+
}
|
|
58
54
|
|
|
59
55
|
if (this.filterContext.length > 0) {
|
|
60
|
-
if (this.filterContext.includes(
|
|
61
|
-
|
|
56
|
+
if (this.filterContext.includes("error")) {
|
|
57
|
+
if (useTrace) {
|
|
58
|
+
this.logger.error(message, { trace: useTrace, ...optionalParams });
|
|
59
|
+
} else {
|
|
60
|
+
this.logger.error(message, ...optionalParams);
|
|
61
|
+
}
|
|
62
62
|
}
|
|
63
63
|
} else {
|
|
64
|
-
|
|
64
|
+
if (useTrace) {
|
|
65
|
+
this.logger.error(message, { trace: useTrace, ...optionalParams });
|
|
66
|
+
} else {
|
|
67
|
+
this.logger.error(message, ...optionalParams);
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
public debug(message: any,
|
|
69
|
-
this.
|
|
72
|
+
public debug(message: any, ...optionalParams: any) {
|
|
73
|
+
if (this.filterContext.length > 0) {
|
|
74
|
+
if (this.filterContext.includes("debug")) {
|
|
75
|
+
this.logger.debug(message, ...optionalParams);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
this.logger.debug(message, ...optionalParams);
|
|
79
|
+
}
|
|
70
80
|
}
|
|
71
81
|
|
|
72
|
-
public verbose(message: any,
|
|
73
|
-
this.
|
|
82
|
+
public verbose(message: any, ...optionalParams: any): any {
|
|
83
|
+
if (this.filterContext.length > 0) {
|
|
84
|
+
if (this.filterContext.includes("verbose")) {
|
|
85
|
+
this.logger.verbose(message, ...optionalParams);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
this.logger.verbose(message, ...optionalParams);
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
|
|
76
|
-
public warn(message: any,
|
|
77
|
-
this.
|
|
92
|
+
public warn(message: any, ...optionalParams: any): any {
|
|
93
|
+
if (this.filterContext.length > 0) {
|
|
94
|
+
if (this.filterContext.includes("warn")) {
|
|
95
|
+
this.logger.warn(message, ...optionalParams);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
this.logger.warn(message, ...optionalParams);
|
|
99
|
+
}
|
|
78
100
|
}
|
|
79
101
|
|
|
80
|
-
public info(message: any
|
|
81
|
-
this.
|
|
102
|
+
public info(message: any): any {
|
|
103
|
+
if (this.filterContext.length > 0) {
|
|
104
|
+
if (this.filterContext.includes("info")) {
|
|
105
|
+
this.logger.log(message, "info");
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
this.logger.log(message, "info");
|
|
109
|
+
}
|
|
82
110
|
}
|
|
83
111
|
}
|