@cley_faye/boilerplate 3.10.1 → 3.11.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/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
|
@@ -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
|
}
|
|
@@ -134,10 +134,8 @@ const getOutputToWatch = (webpackOptions, targetName) => {
|
|
|
134
134
|
if (webpackOptions.output) {
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
: [targetName];
|
|
140
|
-
return entries.map(entryName => (0, path_1.join)("dist", targetName, "js", `${entryName}.js`));
|
|
137
|
+
// Watch all output directory, since webpack generate chunks
|
|
138
|
+
return [(0, path_1.join)("dist", targetName, "js", "*.js")];
|
|
141
139
|
};
|
|
142
140
|
const getWatchTasks = (webpackOptions, targetName) => {
|
|
143
141
|
const outputToWatch = getOutputToWatch(webpackOptions, targetName);
|
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,6 +13,7 @@ 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 {
|
|
18
19
|
cause?: Error;
|
|
@@ -26,8 +27,8 @@ interface ExtendedErrorFields {
|
|
|
26
27
|
}
|
|
27
28
|
declare type ExtendedError = Error & ExtendedErrorFields;
|
|
28
29
|
/** Return a string with the full error and stacktrace, including causes */
|
|
29
|
-
export declare const filterError: (error: ExtendedError, collapseStacktrace?: boolean) => string;
|
|
30
|
-
export declare const customFormat: (timestamp?: boolean, collapseStacktrace?: boolean) => Format;
|
|
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;
|
|
31
32
|
/** Edit the configuration applied to consoleLogger */
|
|
32
33
|
export declare const setConfig: (config: LogConfig) => void;
|
|
33
34
|
export declare const transports: winston.transports.ConsoleTransportInstance[];
|
package/lib/winston.js
CHANGED
|
@@ -31,17 +31,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
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 = true) => {
|
|
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 = true) => {
|
|
|
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));
|
|
@@ -168,16 +179,19 @@ const getErrorFromTransformable = (info) => {
|
|
|
168
179
|
return meta.error;
|
|
169
180
|
}
|
|
170
181
|
};
|
|
171
|
-
const customFormat = (timestamp, collapseStacktrace) => winston_1.default.format.printf((info) => {
|
|
182
|
+
const customFormat = (timestamp, collapseStacktrace, stacktraceFilter) => winston_1.default.format.printf((info) => {
|
|
172
183
|
const effectiveTimestamp = timestamp === undefined
|
|
173
184
|
? logConfig.timestamp
|
|
174
185
|
: timestamp;
|
|
175
186
|
const effectiveCollapse = collapseStacktrace === undefined
|
|
176
187
|
? logConfig.collapseNodeModules || logConfig.collapseStacktrace
|
|
177
188
|
: collapseStacktrace;
|
|
189
|
+
const effectiveStacktraceFilter = stacktraceFilter === undefined
|
|
190
|
+
? logConfig.stacktraceFilter
|
|
191
|
+
: stacktraceFilter;
|
|
178
192
|
const error = getErrorFromTransformable(info);
|
|
179
193
|
const message = error
|
|
180
|
-
? (0, exports.filterError)(error, effectiveCollapse)
|
|
194
|
+
? (0, exports.filterError)(error, effectiveCollapse, effectiveStacktraceFilter)
|
|
181
195
|
: info.message.toString();
|
|
182
196
|
return (0, exports.prefixOutput)(info.level, message, effectiveTimestamp);
|
|
183
197
|
});
|