返回提交历史
Modified
src/utils/logger.ts
+8
-47
XFEstudio/XFESpaceNinjaServer
chore: unaidsify the log files (#3953)
Also removed the useless version number from console log. Closes #3951 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3953 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
c4e70046
代码差异
1 个文件
+8
-47
@@ -2,53 +2,18 @@ import type { LeveledLogMethod } from "winston";
2
2
import { createLogger, format, transports, addColors } from "winston";
3
3
import "winston-daily-rotate-file";
4
4
import { config } from "../services/configService.ts";
5
import * as util from "util";
6
import { isEmptyObject } from "../helpers/general.ts";
7
5
8
// const combineMessageAndSplat = () => {
9
// return {
10
// transform: (info: any, _opts: any) => {
11
// //combine message and args if any
12
// info.message = util.format(info.message, ...(info[Symbol.for("splat")] || []));
13
// return info;
14
// }
15
// };
16
// };
17
18
// const alwaysAddMetadata = () => {
19
// return {
20
// transform(info: any) {
21
// if (info[Symbol.for("splat")] === undefined) return info;
22
// info.meta = info[Symbol.for("splat")]; //[0].meta;
23
// return info;
24
// }
25
// };
26
// };
27
28
//TODO: in production utils.inspect might be slowing down requests see utils.inspect
29
const consolelogFormat = format.printf(info => {
30
if (!isEmptyObject(info.metadata)) {
31
const metadataString = util.inspect(info.metadata, {
32
showHidden: false,
33
depth: null,
34
colors: true
35
});
36
37
return `${info.timestamp as string} [${info.version as string}] ${info.level}: ${info.message as string} ${metadataString}`;
38
}
39
return `${info.timestamp as string} [${info.version as string}] ${info.level}: ${info.message as string}`;
6
const printf = format.printf(info => {
7
return `${info.timestamp as string} [${info.level}] ${info.message as string}`;
40
8
});
41
9
42
const fileFormat = format.combine(
43
format.uncolorize(),
44
//combineMessageAndSplat(),
45
format.timestamp(),
46
format.json()
47
);
48
49
10
const fileLog = new transports.DailyRotateFile({
50
11
filename: `logs/${config.logger.level}.log`,
51
format: fileFormat,
12
format: format.combine(
13
format.uncolorize(),
14
format.timestamp(), // zulu time
15
printf
16
),
52
17
datePattern: "YYYY-MM-DD"
53
18
});
54
19
@@ -57,12 +22,8 @@ const consoleLog = new transports.Console({
57
22
format: format.combine(
58
23
format.colorize(),
59
24
format.timestamp({ format: "YYYY-MM-DDTHH:mm:ss:SSS" }), // uses local timezone
60
//combineMessageAndSplat(),
61
//alwaysAddMetadata(),
62
25
format.errors({ stack: true }),
63
format.align(),
64
format.metadata({ fillExcept: ["message", "level", "timestamp", "version"] }),
65
consolelogFormat
26
printf
66
27
)
67
28
});
68
29