@cley_faye/boilerplate 3.10.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/express/logger.d.ts +1 -0
- package/lib/express/logger.js +11 -4
- package/lib/express/pipelinebuilder.d.ts +1 -0
- package/lib/winston.d.ts +17 -2
- package/lib/winston.js +25 -8
- package/package.json +1 -1
package/lib/express/logger.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface ErrorLoggerConfiguration {
|
|
|
6
6
|
/** @deprecated Use collapseStacktrace */
|
|
7
7
|
collapseNodeModules?: boolean;
|
|
8
8
|
collapseStacktrace?: boolean;
|
|
9
|
+
extraFilter?: Array<RegExp> | RegExp;
|
|
9
10
|
}
|
|
10
11
|
export declare type ErrorLoggerOptions = ErrorLoggerConfiguration | boolean;
|
|
11
12
|
export interface LoggingData {
|
package/lib/express/logger.js
CHANGED
|
@@ -53,7 +53,7 @@ const customRouteFormat = (outputTimestamp) => winston_1.default.format.printf((
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
const metaString = JSON.stringify(info.meta);
|
|
56
|
-
const finalMessage = `${info.message} ${metaString === "{}" ? "" : metaString}`;
|
|
56
|
+
const finalMessage = `${info.message.toString()} ${metaString === "{}" ? "" : metaString}`;
|
|
57
57
|
return (0, winston_js_1.prefixOutput)(info.level, finalMessage, outputTimestamp);
|
|
58
58
|
});
|
|
59
59
|
/** Return the default value for route logger is it is set as `true` */
|
|
@@ -88,8 +88,7 @@ const registerRouteLogger = (app, logOptions) => {
|
|
|
88
88
|
requestWhitelist: ["body"],
|
|
89
89
|
bodyWhitelist: [],
|
|
90
90
|
expressFormat: false,
|
|
91
|
-
format:
|
|
92
|
-
colorize: true,
|
|
91
|
+
format: customRouteFormat(timestamp),
|
|
93
92
|
msg: "{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms",
|
|
94
93
|
};
|
|
95
94
|
app.use(express_winston_1.default.logger({
|
|
@@ -99,6 +98,14 @@ const registerRouteLogger = (app, logOptions) => {
|
|
|
99
98
|
}));
|
|
100
99
|
};
|
|
101
100
|
exports.registerRouteLogger = registerRouteLogger;
|
|
101
|
+
const getExtraFilter = (userExtraFilter) => {
|
|
102
|
+
const expressRegEx = /node_modules\/express/u;
|
|
103
|
+
if (!userExtraFilter)
|
|
104
|
+
return expressRegEx;
|
|
105
|
+
if (Array.isArray(userExtraFilter))
|
|
106
|
+
return [expressRegEx, ...userExtraFilter];
|
|
107
|
+
return [expressRegEx, userExtraFilter];
|
|
108
|
+
};
|
|
102
109
|
const registerErrorLogger = (app, logOptions) => {
|
|
103
110
|
const { error, logger, timestamp } = logOptions ?? {};
|
|
104
111
|
const config = typeof error === "boolean"
|
|
@@ -114,7 +121,7 @@ const registerErrorLogger = (app, logOptions) => {
|
|
|
114
121
|
else {
|
|
115
122
|
app.use(express_winston_1.default.errorLogger({
|
|
116
123
|
transports: winston_js_1.transports,
|
|
117
|
-
format: (0, winston_js_1.customFormat)(timestamp, config.collapseStacktrace ?? config.collapseNodeModules),
|
|
124
|
+
format: (0, winston_js_1.customFormat)(timestamp, config.collapseStacktrace ?? config.collapseNodeModules, getExtraFilter(config.extraFilter)),
|
|
118
125
|
meta: false,
|
|
119
126
|
}));
|
|
120
127
|
}
|
package/lib/winston.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Format } from "logform";
|
|
|
3
3
|
/**
|
|
4
4
|
* Collapse useless lines in stacktrace
|
|
5
5
|
*/
|
|
6
|
-
export declare const filterStacktrace: (message: string) => Generator<string>;
|
|
6
|
+
export declare const filterStacktrace: (message: string, extraFilter?: Array<RegExp> | RegExp) => Generator<string>;
|
|
7
7
|
/**
|
|
8
8
|
* Prefix all lines with the level and the timestamp if needed
|
|
9
9
|
*/
|
|
@@ -13,9 +13,24 @@ export interface LogConfig {
|
|
|
13
13
|
/** @deprecated Use collapseStacktrace instead */
|
|
14
14
|
collapseNodeModules: boolean;
|
|
15
15
|
collapseStacktrace: boolean;
|
|
16
|
+
stacktraceFilter?: Array<RegExp> | RegExp;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
+
interface ExtendedErrorFields {
|
|
19
|
+
cause?: Error;
|
|
20
|
+
response?: {
|
|
21
|
+
data?: string | Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
request?: {
|
|
24
|
+
_currentUrl?: string;
|
|
25
|
+
};
|
|
26
|
+
statusCode?: number;
|
|
27
|
+
}
|
|
28
|
+
declare type ExtendedError = Error & ExtendedErrorFields;
|
|
29
|
+
/** Return a string with the full error and stacktrace, including causes */
|
|
30
|
+
export declare const filterError: (error: ExtendedError, collapseStacktrace?: boolean, extraFilter?: Array<RegExp> | RegExp) => string;
|
|
31
|
+
export declare const customFormat: (timestamp?: boolean, collapseStacktrace?: boolean, stacktraceFilter?: Array<RegExp> | RegExp) => Format;
|
|
18
32
|
/** Edit the configuration applied to consoleLogger */
|
|
19
33
|
export declare const setConfig: (config: LogConfig) => void;
|
|
20
34
|
export declare const transports: winston.transports.ConsoleTransportInstance[];
|
|
21
35
|
export declare const consoleLogger: winston.Logger;
|
|
36
|
+
export {};
|
package/lib/winston.js
CHANGED
|
@@ -29,19 +29,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.consoleLogger = exports.transports = exports.setConfig = exports.customFormat = exports.prefixOutput = exports.filterStacktrace = void 0;
|
|
32
|
+
exports.consoleLogger = exports.transports = exports.setConfig = exports.customFormat = exports.filterError = exports.prefixOutput = exports.filterStacktrace = void 0;
|
|
33
33
|
const winston_1 = __importDefault(require("winston"));
|
|
34
|
-
// High value because of colorize()
|
|
35
34
|
const LOG_LEVEL_PADDING_SIZE = 10;
|
|
36
35
|
const stackFilterRegex = /(?:at process|at runMicrotasks)/u;
|
|
36
|
+
const isFiltered = (line, extraFilter) => {
|
|
37
|
+
if (stackFilterRegex.exec(line))
|
|
38
|
+
return true;
|
|
39
|
+
if (extraFilter) {
|
|
40
|
+
for (const filter of Array.isArray(extraFilter) ? extraFilter : [extraFilter]) {
|
|
41
|
+
if (filter.exec(line))
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
37
47
|
/**
|
|
38
48
|
* Collapse useless lines in stacktrace
|
|
39
49
|
*/
|
|
40
|
-
const filterStacktrace = function* (message) {
|
|
50
|
+
const filterStacktrace = function* (message, extraFilter) {
|
|
41
51
|
let inCollapse = false;
|
|
42
52
|
const lines = message.split("\n");
|
|
43
53
|
for (const line of lines) {
|
|
44
|
-
if (
|
|
54
|
+
if (isFiltered(line, extraFilter)) {
|
|
45
55
|
if (!inCollapse) {
|
|
46
56
|
inCollapse = true;
|
|
47
57
|
yield "[...]";
|
|
@@ -71,6 +81,7 @@ const logConfig = {
|
|
|
71
81
|
timestamp: true,
|
|
72
82
|
collapseNodeModules: true,
|
|
73
83
|
collapseStacktrace: true,
|
|
84
|
+
stacktraceFilter: undefined,
|
|
74
85
|
};
|
|
75
86
|
const indent = (msg, indentLevel) => {
|
|
76
87
|
if (indentLevel === 0)
|
|
@@ -127,7 +138,7 @@ const addHttpErrorContent = (error) => {
|
|
|
127
138
|
return `HttpError status: ${error.statusCode}`;
|
|
128
139
|
};
|
|
129
140
|
/** Return a string with the full error and stacktrace, including causes */
|
|
130
|
-
const filterError = (error, collapseStacktrace) => {
|
|
141
|
+
const filterError = (error, collapseStacktrace = true, extraFilter) => {
|
|
131
142
|
const resultRows = [];
|
|
132
143
|
let cursor = error;
|
|
133
144
|
let indentLevel = 0;
|
|
@@ -141,7 +152,7 @@ const filterError = (error, collapseStacktrace) => {
|
|
|
141
152
|
resultRows.push(indent(cursor.message, indentLevel));
|
|
142
153
|
if (cursor.stack) {
|
|
143
154
|
if (collapseStacktrace) {
|
|
144
|
-
resultRows.push(indent([...(0, exports.filterStacktrace)(cursor.stack)].join("\n"), indentLevel));
|
|
155
|
+
resultRows.push(indent([...(0, exports.filterStacktrace)(cursor.stack, extraFilter)].join("\n"), indentLevel));
|
|
145
156
|
}
|
|
146
157
|
else {
|
|
147
158
|
resultRows.push(indent(cursor.stack, indentLevel));
|
|
@@ -158,6 +169,7 @@ const filterError = (error, collapseStacktrace) => {
|
|
|
158
169
|
}
|
|
159
170
|
return resultRows.join("\n");
|
|
160
171
|
};
|
|
172
|
+
exports.filterError = filterError;
|
|
161
173
|
const getErrorFromTransformable = (info) => {
|
|
162
174
|
if (info instanceof Error)
|
|
163
175
|
return info;
|
|
@@ -167,15 +179,20 @@ const getErrorFromTransformable = (info) => {
|
|
|
167
179
|
return meta.error;
|
|
168
180
|
}
|
|
169
181
|
};
|
|
170
|
-
const customFormat = (timestamp, collapseStacktrace) => winston_1.default.format.printf((info) => {
|
|
182
|
+
const customFormat = (timestamp, collapseStacktrace, stacktraceFilter) => winston_1.default.format.printf((info) => {
|
|
171
183
|
const effectiveTimestamp = timestamp === undefined
|
|
172
184
|
? logConfig.timestamp
|
|
173
185
|
: timestamp;
|
|
174
186
|
const effectiveCollapse = collapseStacktrace === undefined
|
|
175
187
|
? logConfig.collapseNodeModules || logConfig.collapseStacktrace
|
|
176
188
|
: collapseStacktrace;
|
|
189
|
+
const effectiveStacktraceFilter = stacktraceFilter === undefined
|
|
190
|
+
? logConfig.stacktraceFilter
|
|
191
|
+
: stacktraceFilter;
|
|
177
192
|
const error = getErrorFromTransformable(info);
|
|
178
|
-
const message = error
|
|
193
|
+
const message = error
|
|
194
|
+
? (0, exports.filterError)(error, effectiveCollapse, effectiveStacktraceFilter)
|
|
195
|
+
: info.message.toString();
|
|
179
196
|
return (0, exports.prefixOutput)(info.level, message, effectiveTimestamp);
|
|
180
197
|
});
|
|
181
198
|
exports.customFormat = customFormat;
|