skyeye-svc-common-utils 2.0.0-dev0.31 → 2.0.0-dev0.32
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.
|
@@ -11,19 +11,19 @@ const appConfig_1 = require("../appConfig");
|
|
|
11
11
|
const dateformat_1 = __importDefault(require("dateformat"));
|
|
12
12
|
// ensure log directory exists
|
|
13
13
|
fs_1.default.existsSync(appConfig_1.commonAppConfig.LogPath) || fs_1.default.mkdirSync(appConfig_1.commonAppConfig.LogPath);
|
|
14
|
-
|
|
14
|
+
const FileNameGenerator = (time, index) => {
|
|
15
15
|
if (!time) {
|
|
16
16
|
time = new Date();
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
const indexStr = index ? ("-" + JSON.stringify(index)) : "";
|
|
19
19
|
return `backend-access-${(0, dateformat_1.default)(time, 'yyyy-mm-dd')}${indexStr}.log`;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
// create a rotating write stream
|
|
22
|
-
|
|
22
|
+
const accessLogStream = rotating_file_stream_1.default.createStream(FileNameGenerator, {
|
|
23
23
|
interval: '1d',
|
|
24
24
|
path: appConfig_1.commonAppConfig.LogPath
|
|
25
25
|
});
|
|
26
|
-
const jsonFormat =
|
|
26
|
+
const jsonFormat = (tokens, req, res) => {
|
|
27
27
|
return JSON.stringify({
|
|
28
28
|
"method": tokens.method(req, res),
|
|
29
29
|
"url": tokens.url(req, res),
|
|
@@ -36,6 +36,6 @@ const jsonFormat = function (tokens, req, res) {
|
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
38
|
// setup the logger
|
|
39
|
-
exports.morganFile = (0, morgan_1.default)(jsonFormat, { stream: accessLogStream
|
|
39
|
+
exports.morganFile = (0, morgan_1.default)(jsonFormat, { stream: accessLogStream });
|
|
40
40
|
exports.morganConsole = (0, morgan_1.default)(jsonFormat);
|
|
41
41
|
//# sourceMappingURL=morganLogger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"morganLogger.js","sourceRoot":"","sources":["../../../src/utils/logger/morganLogger.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,oDAA4B;AAC5B,gFAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"morganLogger.js","sourceRoot":"","sources":["../../../src/utils/logger/morganLogger.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,oDAA4B;AAC5B,gFAAuC;AACvC,4CAA+C;AAC/C,4DAAoC;AAEpC,8BAA8B;AAC9B,YAAE,CAAC,UAAU,CAAC,2BAAe,CAAC,OAAO,CAAC,IAAI,YAAE,CAAC,SAAS,CAAC,2BAAe,CAAC,OAAO,CAAC,CAAC;AAEhF,MAAM,iBAAiB,GAAG,CAAC,IAAmB,EAAE,KAAa,EAAE,EAAE;IAC7D,IAAI,CAAC,IAAI,EAAE;QACP,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;KACrB;IAED,MAAM,QAAQ,GAAa,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC,EAAE,CAAC;IACrE,OAAO,kBAAkB,IAAA,oBAAU,EAAC,IAAI,EAAC,YAAY,CAAC,GAAG,QAAQ,MAAM,CAAC;AAC5E,CAAC,CAAA;AAED,iCAAiC;AACjC,MAAM,eAAe,GAAG,8BAAG,CAAC,YAAY,CAAC,iBAAiB,EAAE;IACxD,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,2BAAe,CAAC,OAAO;CAChC,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,CAAC,MAAW,EAAE,GAAQ,EAAE,GAAQ,EAAE,EAAE;IACnD,OAAO,IAAI,CAAC,SAAS,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;QACjC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;QAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC;QACvD,cAAc,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;QACxD,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;QAClD,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC;QAC/C,SAAS,EAAE,2BAAe,CAAC,OAAO;KACnC,CAAC,CAAA;AACR,CAAC,CAAA;AAED,mBAAmB;AACN,QAAA,UAAU,GAAG,IAAA,gBAAM,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;AAE7D,QAAA,aAAa,GAAI,IAAA,gBAAM,EAAC,UAAU,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skyeye-svc-common-utils",
|
|
3
|
-
"version": "2.0.0-dev0.
|
|
3
|
+
"version": "2.0.0-dev0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"elastic-apm-node": "^3.5.0",
|
|
37
37
|
"express": "^4.17.1",
|
|
38
38
|
"https": "^1.0.0",
|
|
39
|
-
"ioredis": "^5.
|
|
39
|
+
"ioredis": "^5.3.2",
|
|
40
40
|
"jsonwebtoken": "^9.0.0",
|
|
41
41
|
"lodash": "^4.17.21",
|
|
42
42
|
"moment": "^2.24.0",
|
|
43
43
|
"morgan": "^1.9.1",
|
|
44
44
|
"node-fetch": "^2.6.0",
|
|
45
|
-
"rotating-file-stream": "^
|
|
45
|
+
"rotating-file-stream": "^3.2.1",
|
|
46
46
|
"skyeye-common-const": "1.0.42",
|
|
47
47
|
"swagger-jsdoc": "^3.5.0",
|
|
48
48
|
"typeorm": "^0.3.17",
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import morgan from 'morgan';
|
|
3
3
|
import rfs from 'rotating-file-stream';
|
|
4
|
-
import {commonAppConfig} from '../appConfig';
|
|
4
|
+
import { commonAppConfig } from '../appConfig';
|
|
5
5
|
import dateformat from 'dateformat';
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
// ensure log directory exists
|
|
8
|
-
fs.existsSync(commonAppConfig.LogPath) || fs.mkdirSync(commonAppConfig.LogPath)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (!time)
|
|
12
|
-
{
|
|
8
|
+
fs.existsSync(commonAppConfig.LogPath) || fs.mkdirSync(commonAppConfig.LogPath);
|
|
9
|
+
|
|
10
|
+
const FileNameGenerator = (time: number | Date, index: number) => {
|
|
11
|
+
if (!time) {
|
|
13
12
|
time = new Date();
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
const indexStr : string = index ? ("-" + JSON.stringify(index)): "";
|
|
16
16
|
return `backend-access-${dateformat(time,'yyyy-mm-dd')}${indexStr}.log`;
|
|
17
|
-
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
// create a rotating write stream
|
|
21
|
-
|
|
20
|
+
const accessLogStream = rfs.createStream(FileNameGenerator, {
|
|
22
21
|
interval: '1d', // rotate daily
|
|
23
22
|
path: commonAppConfig.LogPath
|
|
24
|
-
})
|
|
25
|
-
|
|
23
|
+
});
|
|
26
24
|
|
|
27
|
-
const jsonFormat =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
const jsonFormat = (tokens: any, req: any, res: any) => {
|
|
26
|
+
return JSON.stringify({
|
|
27
|
+
"method": tokens.method(req, res),
|
|
28
|
+
"url": tokens.url(req, res),
|
|
29
|
+
"status": tokens.status(req, res),
|
|
30
|
+
"contentLength": tokens.res(req, res, 'content-length'),
|
|
31
|
+
"responseTime": tokens['response-time'](req, res) + 'ms',
|
|
32
|
+
"totalTime": tokens['total-time'](req, res) + 'ms',
|
|
33
|
+
"httpVersion": tokens['http-version'](req, res),
|
|
34
|
+
"service": commonAppConfig.AppName
|
|
35
|
+
})
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
// setup the logger
|
|
41
|
-
export const morganFile = morgan(jsonFormat, { stream: accessLogStream
|
|
39
|
+
export const morganFile = morgan(jsonFormat, { stream: accessLogStream });
|
|
42
40
|
|
|
43
41
|
export const morganConsole = morgan(jsonFormat)
|