From ccbdfceb3f540f19bb1ab97d1f0507eb3577e5eb Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 16 Sep 2021 15:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E4=B8=8E=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/globalData.js | 3 +++ src/lang/en_us.json | 1 + src/lang/zh_cn.json | 1 + src/plugins/sync/client/auth.js | 2 -- src/plugins/sync/client/client.js | 1 + src/plugins/sync/client/index.js | 10 +++++++++- src/screens/Home/Setting/Other/Log.js | 16 ++++++++++++++-- src/utils/log.js | 4 ++-- 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/config/globalData.js b/src/config/globalData.js index 70d4449..43bf40b 100644 --- a/src/config/globalData.js +++ b/src/config/globalData.js @@ -28,3 +28,6 @@ global.playInfo = { currentPlayMusicInfo: null, duration: 0, } + +global.isEnableSyncLog = false + diff --git a/src/lang/en_us.json b/src/lang/en_us.json index 42f6503..11be6a6 100644 --- a/src/lang/en_us.json +++ b/src/lang/en_us.json @@ -126,6 +126,7 @@ "setting_other_log_btn_clean": "Clear", "setting_other_log_btn_hide": "Close", "setting_other_log_btn_show": "View log", + "setting_other_log_sync_error_log": "Record synchronization connection failure error log", "setting_other_log_tip_clean_success": "Log cleaning completed", "setting_other_log_tip_null": "The log is empty~", "setting_play": "Play", diff --git a/src/lang/zh_cn.json b/src/lang/zh_cn.json index 69e66aa..bdefa38 100644 --- a/src/lang/zh_cn.json +++ b/src/lang/zh_cn.json @@ -126,6 +126,7 @@ "setting_other_log_btn_clean": "清空", "setting_other_log_btn_hide": "关闭", "setting_other_log_btn_show": "查看日志", + "setting_other_log_sync_error_log": "记录同步连接失败错误日志", "setting_other_log_tip_clean_success": "日志清理完成", "setting_other_log_tip_null": "日志是空的哦~", "setting_play": "播放设置", diff --git a/src/plugins/sync/client/auth.js b/src/plugins/sync/client/auth.js index 6d23fa0..c99a226 100644 --- a/src/plugins/sync/client/auth.js +++ b/src/plugins/sync/client/auth.js @@ -33,7 +33,6 @@ const codeAuth = async(host, port, serverId, authCode) => { try { msg = aesDecrypt(text, key, iv) } catch (err) { - log.warn(err.stack) throw new Error(SYNC_CODE.authFailed) } if (!msg) return Promise.reject(new Error(SYNC_CODE.authFailed)) @@ -50,7 +49,6 @@ const keyAuth = async(host, port, keyInfo) => { try { msg = aesDecrypt(text, keyInfo.key, keyInfo.iv) } catch (err) { - log.warn(err.stack) throw new Error(SYNC_CODE.authFailed) } if (msg != SYNC_CODE.helloMsg) return Promise.reject(new Error(SYNC_CODE.authFailed)) diff --git a/src/plugins/sync/client/client.js b/src/plugins/sync/client/client.js index f0a22a0..9f1e8ab 100644 --- a/src/plugins/sync/client/client.js +++ b/src/plugins/sync/client/client.js @@ -43,6 +43,7 @@ export const connect = (host, port, keyInfo) => { }) socket.on('connect_error', (err) => { console.log(err.message) + if (global.isEnableSyncLog) log.error(err.stack) const store = getStore() store.dispatch(commonAction.setSyncStatus({ status: false, diff --git a/src/plugins/sync/client/index.js b/src/plugins/sync/client/index.js index 5d31eb8..2742f49 100644 --- a/src/plugins/sync/client/index.js +++ b/src/plugins/sync/client/index.js @@ -36,7 +36,15 @@ const connect = authCode => { status: false, message: err.message, })) - log.warn(err.message) + switch (err.message) { + case SYNC_CODE.connectServiceFailed: + case SYNC_CODE.missingAuthCode: + break + default: + log.warn(err.message) + break + } + return Promise.reject(err) }) } diff --git a/src/screens/Home/Setting/Other/Log.js b/src/screens/Home/Setting/Other/Log.js index ca0a692..641f766 100644 --- a/src/screens/Home/Setting/Other/Log.js +++ b/src/screens/Home/Setting/Other/Log.js @@ -9,6 +9,7 @@ import Button from '../components/Button' import { useTranslation } from '@/plugins/i18n' import { toast } from '@/utils/tools' import ConfirmAlert from '@/components/common/ConfirmAlert' +import CheckBoxItem from '../components/CheckBoxItem' export default memo(() => { const { t } = useTranslation() @@ -16,13 +17,15 @@ export default memo(() => { const [logText, setLogText] = useState('') const theme = useGetter('common', 'theme') const isUnmountedRef = useRef(true) + const [isEnableSyncErrorLog, setIsEnableSyncErrorLog] = useState(false) const getErrorLog = () => { getLogs().then(log => { if (isUnmountedRef.current) return - const logArr = log.split('\n\n') + const logArr = log.split(/^----lx log----\n|\n----lx log----\n|\n----lx log----$/) + // console.log(logArr) logArr.reverse() - setLogText(logArr.join('\n').replace(/\n+$/, '')) + setLogText(logArr.join('\n\n').replace(/^\n+|\n+$/, '')) }) } @@ -42,9 +45,15 @@ export default memo(() => { }) } + const handleSetEnableSyncErrorLog = enable => { + setIsEnableSyncErrorLog(enable) + global.isEnableSyncLog = enable + } + useEffect(() => { isUnmountedRef.current = false + setIsEnableSyncErrorLog(global.isEnableSyncLog) return () => { isUnmountedRef.current = true } @@ -54,6 +63,9 @@ export default memo(() => { return ( <> + + + diff --git a/src/utils/log.js b/src/utils/log.js index 9f6e53d..41f95dd 100644 --- a/src/utils/log.js +++ b/src/utils/log.js @@ -7,13 +7,13 @@ const logTools = { tempLog: [], writeLog(msg) { console.log(msg) - appendFile(logPath, '\n' + msg) + appendFile(logPath, '\n----lx log----\n' + msg) }, async initLogFile() { try { let isExists = await existsFile(logPath) if (!isExists) await writeFile(logPath, '') - if (this.tempLog) this.writeLog(this.tempLog.map(m => `${m.time} ${m.type} ${m.text}`).join('\n')) + if (this.tempLog.length) this.writeLog(this.tempLog.map(m => `${m.time} ${m.type} ${m.text}`).join('\n----lx log----\n')) this.tempLog = null } catch (err) { console.error(err)