From af282d715435023f3b6b05bd77f5df75399eb4df Mon Sep 17 00:00:00 2001 From: unitwk Date: Thu, 11 Aug 2022 15:26:28 +0800 Subject: [PATCH] Feat: add some log print & translate --- package.json | 8 ++++---- src/app.ts | 3 ++- src/app/entity/remote_service.ts | 20 ++++++++++++++------ src/app/i18n/language/zh_cn.ts | 17 +++++++++-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 316da72..cd596c4 100755 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/app.ts b/src/app.ts index fd5bb5b..d390c92 100755 --- a/src/app.ts +++ b/src/app.ts @@ -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(); }); diff --git a/src/app/entity/remote_service.ts b/src/app/entity/remote_service.ts index ca48700..334d90e 100755 --- a/src/app/entity/remote_service.ts +++ b/src/app/entity/remote_service.ts @@ -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; } } diff --git a/src/app/i18n/language/zh_cn.ts b/src/app/i18n/language/zh_cn.ts index 9a22485..ea8dc83 100755 --- a/src/app/i18n/language/zh_cn.ts +++ b/src/app/i18n/language/zh_cn.ts @@ -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";