@cley_faye/boilerplate 3.4.1 → 3.5.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.js +3 -35
- package/lib/express/pipelinebuilder.js +10 -0
- package/lib/express.d.ts +3 -0
- package/lib/express.js +3 -0
- package/lib/winston.d.ts +14 -0
- package/lib/winston.js +52 -2
- package/package.json +4 -4
package/lib/express/logger.js
CHANGED
|
@@ -33,38 +33,6 @@ exports.registerErrorLogger = exports.registerRouteLogger = void 0;
|
|
|
33
33
|
const winston_1 = __importDefault(require("winston"));
|
|
34
34
|
const express_winston_1 = __importDefault(require("express-winston"));
|
|
35
35
|
const winston_js_1 = require("../winston.js");
|
|
36
|
-
// High value because of colorize()
|
|
37
|
-
const LOG_LEVEL_PADDING_SIZE = 19;
|
|
38
|
-
/**
|
|
39
|
-
* Collapse all lines containing /node_modules/ into an ellipsis
|
|
40
|
-
*/
|
|
41
|
-
const filterNodeModules = function* (message) {
|
|
42
|
-
let inNodeModules = false;
|
|
43
|
-
const lines = message.split("\n");
|
|
44
|
-
for (const line of lines) {
|
|
45
|
-
if (/\/node_modules\//u.exec(line)) {
|
|
46
|
-
if (!inNodeModules) {
|
|
47
|
-
inNodeModules = true;
|
|
48
|
-
yield "[...]";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
inNodeModules = false;
|
|
53
|
-
yield line;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Prefix all lines with the level and the timestamp if needed
|
|
59
|
-
*/
|
|
60
|
-
const prefixOutput = (level, message, timestamp) => {
|
|
61
|
-
const timestampPrefix = timestamp
|
|
62
|
-
? `${new Date().toISOString()} `
|
|
63
|
-
: "";
|
|
64
|
-
const levelPrefix = `${level.toString().padStart(LOG_LEVEL_PADDING_SIZE)}: `;
|
|
65
|
-
return message.split("\n").map(line => `${timestampPrefix}${levelPrefix}${line}`)
|
|
66
|
-
.join("\n");
|
|
67
|
-
};
|
|
68
36
|
const customRouteFormat = (outputTimestamp) => winston_1.default.format.printf((info) => {
|
|
69
37
|
const meta = info.meta;
|
|
70
38
|
// Clean the meta object from stuff displayed in the regular message
|
|
@@ -86,7 +54,7 @@ const customRouteFormat = (outputTimestamp) => winston_1.default.format.printf((
|
|
|
86
54
|
}
|
|
87
55
|
const metaString = JSON.stringify(info.meta);
|
|
88
56
|
const finalMessage = `${info.message} ${metaString === "{}" ? "" : metaString}`;
|
|
89
|
-
return prefixOutput(info.level, finalMessage, outputTimestamp);
|
|
57
|
+
return (0, winston_js_1.prefixOutput)(info.level, finalMessage, outputTimestamp);
|
|
90
58
|
});
|
|
91
59
|
const registerRouteLogger = (app, logOptions) => {
|
|
92
60
|
const { route, logger, timestamp } = logOptions ?? {};
|
|
@@ -131,9 +99,9 @@ const customErrorFormat = (outputTimestamp, config) => {
|
|
|
131
99
|
return winston_1.default.format.printf((info) => {
|
|
132
100
|
const meta = info.meta;
|
|
133
101
|
const finalMessage = collapseNodeModules
|
|
134
|
-
? [...filterNodeModules(meta.message)].join("\n")
|
|
102
|
+
? [...(0, winston_js_1.filterNodeModules)(meta.message)].join("\n")
|
|
135
103
|
: meta.message;
|
|
136
|
-
return prefixOutput(info.level, finalMessage, outputTimestamp);
|
|
104
|
+
return (0, winston_js_1.prefixOutput)(info.level, finalMessage, outputTimestamp);
|
|
137
105
|
});
|
|
138
106
|
};
|
|
139
107
|
const registerErrorLogger = (app, logOptions) => {
|
|
@@ -30,6 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
const express_1 = __importDefault(require("express"));
|
|
33
|
+
const winston_js_1 = require("../winston.js");
|
|
33
34
|
const logger_js_1 = require("./logger.js");
|
|
34
35
|
const defaultErrorHandler = (err, req, res, next) => {
|
|
35
36
|
if (!res.headersSent && err.statusCode) {
|
|
@@ -88,6 +89,15 @@ class PipelineBuilder {
|
|
|
88
89
|
createPipeline({ topLevels, routes, statics, postStatics, errorHandlers, options, }) {
|
|
89
90
|
const { middleware, log, defaultErrorHandler: useDefaultErrorHandler } = options ?? {};
|
|
90
91
|
this.internalLog("createPipeline()");
|
|
92
|
+
if (log) {
|
|
93
|
+
const errorConfig = typeof log.error === "boolean"
|
|
94
|
+
? {}
|
|
95
|
+
: log.error ?? {};
|
|
96
|
+
(0, winston_js_1.setConfig)({
|
|
97
|
+
timestamp: log.timestamp ?? false,
|
|
98
|
+
collapseNodeModules: errorConfig.collapseNodeModules ?? true,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
91
101
|
const router = express_1.default.Router();
|
|
92
102
|
this.internalLog("setGenericMiddlewares()");
|
|
93
103
|
this._setGenericMiddlewares(router, middleware);
|
package/lib/express.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ import { PipelineSettings, LogFunction } from "./express/pipelinebuilder.js";
|
|
|
23
23
|
* If the request accepts json, a json object with the error is returned.
|
|
24
24
|
* Otherwise text is returned.
|
|
25
25
|
*
|
|
26
|
+
* For convenience, providing timestamp and collapseNodeModules here will automatically
|
|
27
|
+
* update the basic consoleLogger configuration.
|
|
28
|
+
*
|
|
26
29
|
* @param settings
|
|
27
30
|
*
|
|
28
31
|
* @param [settings.topLevels]
|
package/lib/express.js
CHANGED
|
@@ -51,6 +51,9 @@ const pipelinebuilder_js_1 = __importDefault(require("./express/pipelinebuilder.
|
|
|
51
51
|
* If the request accepts json, a json object with the error is returned.
|
|
52
52
|
* Otherwise text is returned.
|
|
53
53
|
*
|
|
54
|
+
* For convenience, providing timestamp and collapseNodeModules here will automatically
|
|
55
|
+
* update the basic consoleLogger configuration.
|
|
56
|
+
*
|
|
54
57
|
* @param settings
|
|
55
58
|
*
|
|
56
59
|
* @param [settings.topLevels]
|
package/lib/winston.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
+
/**
|
|
3
|
+
* Collapse all lines containing /node_modules/ into an ellipsis
|
|
4
|
+
*/
|
|
5
|
+
export declare const filterNodeModules: (message: string) => Generator<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Prefix all lines with the level and the timestamp if needed
|
|
8
|
+
*/
|
|
9
|
+
export declare const prefixOutput: (level: string, message: string, timestamp: boolean | undefined) => string;
|
|
10
|
+
export interface LogConfig {
|
|
11
|
+
timestamp: boolean;
|
|
12
|
+
collapseNodeModules: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Edit the configuration applied to consoleLogger */
|
|
15
|
+
export declare const setConfig: (config: LogConfig) => void;
|
|
2
16
|
export declare const transports: winston.transports.ConsoleTransportInstance[];
|
|
3
17
|
export declare const consoleLogger: winston.Logger;
|
package/lib/winston.js
CHANGED
|
@@ -29,11 +29,61 @@ 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 = void 0;
|
|
32
|
+
exports.consoleLogger = exports.transports = exports.setConfig = exports.prefixOutput = exports.filterNodeModules = void 0;
|
|
33
33
|
const winston_1 = __importDefault(require("winston"));
|
|
34
|
+
// High value because of colorize()
|
|
35
|
+
const LOG_LEVEL_PADDING_SIZE = 19;
|
|
36
|
+
/**
|
|
37
|
+
* Collapse all lines containing /node_modules/ into an ellipsis
|
|
38
|
+
*/
|
|
39
|
+
const filterNodeModules = function* (message) {
|
|
40
|
+
let inNodeModules = false;
|
|
41
|
+
const lines = message.split("\n");
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
if (/\/node_modules\//u.exec(line)) {
|
|
44
|
+
if (!inNodeModules) {
|
|
45
|
+
inNodeModules = true;
|
|
46
|
+
yield "[...]";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
inNodeModules = false;
|
|
51
|
+
yield line;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.filterNodeModules = filterNodeModules;
|
|
56
|
+
/**
|
|
57
|
+
* Prefix all lines with the level and the timestamp if needed
|
|
58
|
+
*/
|
|
59
|
+
const prefixOutput = (level, message, timestamp) => {
|
|
60
|
+
const timestampPrefix = timestamp
|
|
61
|
+
? `${new Date().toISOString()} `
|
|
62
|
+
: "";
|
|
63
|
+
const levelPrefix = `${level.toString().padStart(LOG_LEVEL_PADDING_SIZE)}: `;
|
|
64
|
+
return message.split("\n").map(line => `${timestampPrefix}${levelPrefix}${line}`)
|
|
65
|
+
.join("\n");
|
|
66
|
+
};
|
|
67
|
+
exports.prefixOutput = prefixOutput;
|
|
68
|
+
const logConfig = {
|
|
69
|
+
timestamp: true,
|
|
70
|
+
collapseNodeModules: true,
|
|
71
|
+
};
|
|
72
|
+
const customFormat = winston_1.default.format.printf((info) => {
|
|
73
|
+
const message = ("stack" in info) ? info.stack : info.message;
|
|
74
|
+
const filteredMessage = logConfig.collapseNodeModules
|
|
75
|
+
? [...(0, exports.filterNodeModules)(message)].join("\n")
|
|
76
|
+
: message;
|
|
77
|
+
return (0, exports.prefixOutput)(info.level, filteredMessage, logConfig.timestamp);
|
|
78
|
+
});
|
|
79
|
+
/** Edit the configuration applied to consoleLogger */
|
|
80
|
+
const setConfig = (config) => {
|
|
81
|
+
Object.assign(logConfig, config);
|
|
82
|
+
};
|
|
83
|
+
exports.setConfig = setConfig;
|
|
34
84
|
exports.transports = [new winston_1.default.transports.Console()];
|
|
35
85
|
exports.consoleLogger = winston_1.default.createLogger({
|
|
36
86
|
level: "info",
|
|
37
|
-
format: winston_1.default.format.combine(winston_1.default.format.colorize(),
|
|
87
|
+
format: winston_1.default.format.combine(winston_1.default.format.colorize(), customFormat),
|
|
38
88
|
transports: exports.transports,
|
|
39
89
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cley_faye/boilerplate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Boilerplate code generator for generic projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/CleyFaye/boilerplate#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@keeex/eslint-config": "^1.7.
|
|
20
|
+
"@keeex/eslint-config": "^1.7.1",
|
|
21
21
|
"@types/express": "^4.17.11",
|
|
22
22
|
"@types/grunt": "^0.4.25",
|
|
23
23
|
"@types/http-errors": "^1.8.0",
|
|
24
24
|
"@types/node": "^16.0.0",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
26
|
-
"@typescript-eslint/parser": "^5.
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.12.0",
|
|
27
27
|
"eslint": "^8.7.0",
|
|
28
28
|
"eslint-plugin-import": "^2.25.4",
|
|
29
29
|
"eslint-plugin-promise": "^6.0.0",
|