XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: logger.format config (#3968)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3968 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

ff2e79d9
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

4 个文件 +13 -2
Modified config-vanilla.json +2 -1
@@ -2,7 +2,8 @@
2 2 "mongodbUrl": "mongodb://127.0.0.1:27017/openWF",
3 3 "logger": {
4 4 "files": true,
5 "level": "trace"
5 "level": "trace",
6 "format": "%timestamp% [%level%] %message%"
6 7 },
7 8 "myAddress": "localhost",
8 9 "bindAddress": "0.0.0.0",
Modified src/services/configService.ts +1 -0
@@ -17,6 +17,7 @@ export interface IConfig {
17 17 logger: {
18 18 files: boolean;
19 19 level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
20 format?: string;
20 21 };
21 22 myAddress: string;
22 23 bindAddress?: string;
Modified src/services/configWatcherService.ts +6 -0
@@ -26,6 +26,7 @@ import { createMessage } from "./inboxService.ts";
26 26
27 27 chokidar.watch(configPath).on("change", () => {
28 28 if (shouldReloadConfig()) {
29 const prevLogFormat = config.logger.format ?? "%timestamp% [%level%] %message%";
29 30 const prevTunables = JSON.stringify(config.tunables);
30 31 const prevWebParams = JSON.stringify(getWebServerParams());
31 32
@@ -39,6 +40,11 @@ chokidar.watch(configPath).on("change", () => {
39 40 validateConfig();
40 41 syncConfigWithDatabase();
41 42
43 if ((config.logger.format ?? "%timestamp% [%level%] %message%") != prevLogFormat) {
44 logger.info("Log format changed.");
45 logger.debug("Here's some text to feast your eyes upon.");
46 }
47
42 48 if (JSON.stringify(config.tunables) != prevTunables) {
43 49 logger.debug(`tunables changed, informing clients`);
44 50 forEachWsClient(client => {
Modified src/utils/logger.ts +4 -1
@@ -4,7 +4,10 @@ import "winston-daily-rotate-file";
4 4 import { config } from "../services/configService.ts";
5 5
6 6 const printf = format.printf(info => {
7 return `${info.timestamp as string} [${info.level}] ${info.message as string}`;
7 return (config.logger.format ?? "%timestamp% [%level%] %message%")
8 .replaceAll("%timestamp%", info.timestamp as string)
9 .replaceAll("%level%", info.level)
10 .replaceAll("%message%", info.message as string);
8 11 });
9 12
10 13 const fileLog = new transports.DailyRotateFile({