mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
优化日志记录与显示
This commit is contained in:
parent
9ea332a073
commit
ccbdfceb3f
@ -28,3 +28,6 @@ global.playInfo = {
|
|||||||
currentPlayMusicInfo: null,
|
currentPlayMusicInfo: null,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.isEnableSyncLog = false
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
"setting_other_log_btn_clean": "Clear",
|
"setting_other_log_btn_clean": "Clear",
|
||||||
"setting_other_log_btn_hide": "Close",
|
"setting_other_log_btn_hide": "Close",
|
||||||
"setting_other_log_btn_show": "View log",
|
"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_clean_success": "Log cleaning completed",
|
||||||
"setting_other_log_tip_null": "The log is empty~",
|
"setting_other_log_tip_null": "The log is empty~",
|
||||||
"setting_play": "Play",
|
"setting_play": "Play",
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
"setting_other_log_btn_clean": "清空",
|
"setting_other_log_btn_clean": "清空",
|
||||||
"setting_other_log_btn_hide": "关闭",
|
"setting_other_log_btn_hide": "关闭",
|
||||||
"setting_other_log_btn_show": "查看日志",
|
"setting_other_log_btn_show": "查看日志",
|
||||||
|
"setting_other_log_sync_error_log": "记录同步连接失败错误日志",
|
||||||
"setting_other_log_tip_clean_success": "日志清理完成",
|
"setting_other_log_tip_clean_success": "日志清理完成",
|
||||||
"setting_other_log_tip_null": "日志是空的哦~",
|
"setting_other_log_tip_null": "日志是空的哦~",
|
||||||
"setting_play": "播放设置",
|
"setting_play": "播放设置",
|
||||||
|
@ -33,7 +33,6 @@ const codeAuth = async(host, port, serverId, authCode) => {
|
|||||||
try {
|
try {
|
||||||
msg = aesDecrypt(text, key, iv)
|
msg = aesDecrypt(text, key, iv)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.warn(err.stack)
|
|
||||||
throw new Error(SYNC_CODE.authFailed)
|
throw new Error(SYNC_CODE.authFailed)
|
||||||
}
|
}
|
||||||
if (!msg) return Promise.reject(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 {
|
try {
|
||||||
msg = aesDecrypt(text, keyInfo.key, keyInfo.iv)
|
msg = aesDecrypt(text, keyInfo.key, keyInfo.iv)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.warn(err.stack)
|
|
||||||
throw new Error(SYNC_CODE.authFailed)
|
throw new Error(SYNC_CODE.authFailed)
|
||||||
}
|
}
|
||||||
if (msg != SYNC_CODE.helloMsg) return Promise.reject(new Error(SYNC_CODE.authFailed))
|
if (msg != SYNC_CODE.helloMsg) return Promise.reject(new Error(SYNC_CODE.authFailed))
|
||||||
|
@ -43,6 +43,7 @@ export const connect = (host, port, keyInfo) => {
|
|||||||
})
|
})
|
||||||
socket.on('connect_error', (err) => {
|
socket.on('connect_error', (err) => {
|
||||||
console.log(err.message)
|
console.log(err.message)
|
||||||
|
if (global.isEnableSyncLog) log.error(err.stack)
|
||||||
const store = getStore()
|
const store = getStore()
|
||||||
store.dispatch(commonAction.setSyncStatus({
|
store.dispatch(commonAction.setSyncStatus({
|
||||||
status: false,
|
status: false,
|
||||||
|
@ -36,7 +36,15 @@ const connect = authCode => {
|
|||||||
status: false,
|
status: false,
|
||||||
message: err.message,
|
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)
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import Button from '../components/Button'
|
|||||||
import { useTranslation } from '@/plugins/i18n'
|
import { useTranslation } from '@/plugins/i18n'
|
||||||
import { toast } from '@/utils/tools'
|
import { toast } from '@/utils/tools'
|
||||||
import ConfirmAlert from '@/components/common/ConfirmAlert'
|
import ConfirmAlert from '@/components/common/ConfirmAlert'
|
||||||
|
import CheckBoxItem from '../components/CheckBoxItem'
|
||||||
|
|
||||||
export default memo(() => {
|
export default memo(() => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -16,13 +17,15 @@ export default memo(() => {
|
|||||||
const [logText, setLogText] = useState('')
|
const [logText, setLogText] = useState('')
|
||||||
const theme = useGetter('common', 'theme')
|
const theme = useGetter('common', 'theme')
|
||||||
const isUnmountedRef = useRef(true)
|
const isUnmountedRef = useRef(true)
|
||||||
|
const [isEnableSyncErrorLog, setIsEnableSyncErrorLog] = useState(false)
|
||||||
|
|
||||||
const getErrorLog = () => {
|
const getErrorLog = () => {
|
||||||
getLogs().then(log => {
|
getLogs().then(log => {
|
||||||
if (isUnmountedRef.current) return
|
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()
|
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(() => {
|
useEffect(() => {
|
||||||
isUnmountedRef.current = false
|
isUnmountedRef.current = false
|
||||||
|
setIsEnableSyncErrorLog(global.isEnableSyncLog)
|
||||||
return () => {
|
return () => {
|
||||||
isUnmountedRef.current = true
|
isUnmountedRef.current = true
|
||||||
}
|
}
|
||||||
@ -54,6 +63,9 @@ export default memo(() => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SubTitle title={t('setting_other_log')}>
|
<SubTitle title={t('setting_other_log')}>
|
||||||
|
<View style={{ paddingTop: 10, paddingBottom: 15, marginLeft: -25 }}>
|
||||||
|
<CheckBoxItem check={isEnableSyncErrorLog} label={t('setting_other_log_sync_error_log')} onChange={handleSetEnableSyncErrorLog} />
|
||||||
|
</View>
|
||||||
<View style={styles.btn}>
|
<View style={styles.btn}>
|
||||||
<Button onPress={openLogModal}>{t('setting_other_log_btn_show')}</Button>
|
<Button onPress={openLogModal}>{t('setting_other_log_btn_show')}</Button>
|
||||||
</View>
|
</View>
|
||||||
|
@ -7,13 +7,13 @@ const logTools = {
|
|||||||
tempLog: [],
|
tempLog: [],
|
||||||
writeLog(msg) {
|
writeLog(msg) {
|
||||||
console.log(msg)
|
console.log(msg)
|
||||||
appendFile(logPath, '\n' + msg)
|
appendFile(logPath, '\n----lx log----\n' + msg)
|
||||||
},
|
},
|
||||||
async initLogFile() {
|
async initLogFile() {
|
||||||
try {
|
try {
|
||||||
let isExists = await existsFile(logPath)
|
let isExists = await existsFile(logPath)
|
||||||
if (!isExists) await writeFile(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
|
this.tempLog = null
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user