Feat: add some log print & translate

This commit is contained in:
unitwk 2022-08-11 15:26:28 +08:00
parent 64bcfc8225
commit af282d7154
4 changed files with 29 additions and 19 deletions

View File

@ -1,16 +1,16 @@
{
"name": "mcsmanager-panel",
"version": "9.6.0",
"daemonVersion": "1.6.0",
"description": "Distributed clustering, Groupable, Lightweight and out-of-the-box Minecraft server management panel",
"daemonVersion": "1.7.0",
"description": "Distributed, out-of-the-box, supports docker, supports minecraft server and other software management panel",
"scripts": {
"dev": "nodemon app.js",
"start": "ts-node ./src/app.ts",
"build": "tsc && webpack --config webpack.config.js"
},
"homepage": "https://mcsmanager.com/",
"author": "https://github.com/Suwings",
"license": "AGPL-3.0",
"author": "https://github.com/unitwk",
"license": " Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/MCSManager/MCSManager"

View File

@ -75,7 +75,8 @@ app.use(
// Http log and print
app.use(async (ctx, next) => {
logger.info(`${ctx.ip} ${ctx.method} - ${ctx.URL.href}`);
logger.info(`[HTTP] ${ctx.ip} ${ctx.method} - ${ctx.URL.href}`);
logger.info(`[HTTP] ${ctx.session.userName}`);
await next();
});

View File

@ -5,7 +5,7 @@ import { RemoteServiceConfig } from "./entity_interface";
import { logger } from "../service/log";
import RemoteRequest from "../service/remote_command";
import InstanceStreamListener from "../common/instance_stream";
import { $t } from "../i18n";
import { $t, i18next } from "../i18n";
export default class RemoteService {
public static readonly STATUS_OK = 200;
@ -30,7 +30,7 @@ export default class RemoteService {
if (this.config.ip.indexOf("wss://") === 0 || this.config.ip.indexOf("ws://") === 0) {
addr = `${this.config.ip}:${this.config.port}`;
}
const daemonInfo = `[${this.uuid}] [${addr}]`;
const daemonInfo = `[${this.uuid}] [${addr}/${this.config.remarks}]`;
if (this.available) {
logger.info(`${$t("daemonInfo.resetConnect")}:${daemonInfo}`);
@ -60,7 +60,13 @@ export default class RemoteService {
});
}
public async setLanguage(language: string) {
public async setLanguage(language?: string) {
if (!language) language = i18next.language;
logger.info(
`${$t("daemonInfo.setLanguage")} (${this.config.ip}:${this.config.port}/${
this.config.remarks
}) language: ${language}`
);
return await new RemoteRequest(this).request("info/setting", {
language
});
@ -76,14 +82,16 @@ export default class RemoteService {
const res = await new RemoteRequest(this).request("auth", this.config.apiKey, 5000, true);
if (res === true) {
this.available = true;
logger.info($t("daemonInfo.connect", { v: daemonInfo }));
await this.setLanguage();
logger.info($t("daemonInfo.authSuccess", { v: daemonInfo }));
return true;
}
this.available = false;
logger.warn($t("daemonInfo.disconnect", { v: daemonInfo }));
logger.warn($t("daemonInfo.authFailure", { v: daemonInfo }));
return false;
} catch (error) {
logger.warn($t("daemonInfo.connectError", { v: daemonInfo }));
logger.warn($t("daemonInfo.authError", { v: daemonInfo }));
logger.warn(error);
return false;
}
}

View File

@ -57,16 +57,17 @@ export default {
}
},
daemonInfo: {
connect: "远程节点 {{v}} 已连接",
disconnect: "远程节点 {{v}} 已断开",
connectError: "连接远程节点错误:{{v}} ",
authSuccess: "远程节点 {{v}} 验证成功",
authFailure: "远程节点 {{v}} 验证失败",
authError: "远程节点 {{v}} 验证错误",
closed: "主动断开远程节点 {{v}} ",
connect: "远程节点 {{- v}} 已连接",
disconnect: "远程节点 {{- v}} 已断开",
connectError: "连接远程节点错误:{{- v}} ",
authSuccess: "远程节点 {{- v}} 密钥验证通过",
authFailure: "远程节点 {{- v}} 密钥验证拒绝",
authError: "远程节点 {{- v}} 密钥验证错误",
closed: "主动断开远程节点 {{- v}} ",
resetConnect: "用户发起重连已可用状态的远程节点,正在重置连接通道",
replaceConnect: "用户发起重复连接请求,现进行重置连接配置",
tryConnect: "正在尝试连接远程节点"
tryConnect: "正在尝试连接远程节点",
setLanguage: "设置节点语言"
}
};
// import { $t } from "../../i18n";