feat: add log function

This commit is contained in:
Gabe Yuan
2024-03-19 18:07:18 +08:00
parent 1d9e9c1b7d
commit 6e927473b9
24 changed files with 76 additions and 41 deletions

View File

@@ -21,6 +21,7 @@ import {
} from "../../config";
import { shortcutRegister } from "../../libs/shortcut";
import { sendIframeMsg } from "../../libs/iframe";
import { kissLog } from "../../libs/log";
export default function Action({ translator, fab }) {
const fabWidth = 40;
@@ -138,7 +139,7 @@ export default function Action({ translator, fab }) {
});
};
} catch (err) {
console.log("[registerMenuCommand]", err);
kissLog(err, "registerMenuCommand");
}
}, [translator]);

View File

@@ -18,6 +18,7 @@ import UploadButton from "./UploadButton";
import Button from "@mui/material/Button";
import ClearAllIcon from "@mui/icons-material/ClearAll";
import { isValidWord } from "../../libs/utils";
import { kissLog } from "../../libs/log";
function DictField({ word }) {
const [dictResult, setDictResult] = useState(null);
@@ -93,7 +94,7 @@ export default function FavWords() {
.filter(isValidWord);
await mergeWords(newWords);
} catch (err) {
console.log("[import rules]", err);
kissLog(err, "import rules");
}
};

View File

@@ -59,6 +59,7 @@ import AddIcon from "@mui/icons-material/Add";
import EditIcon from "@mui/icons-material/Edit";
import CancelIcon from "@mui/icons-material/Cancel";
import SaveIcon from "@mui/icons-material/Save";
import { kissLog } from "../../libs/log";
function RuleFields({ rule, rules, setShow, setKeyword }) {
const initFormValues = {
@@ -701,7 +702,7 @@ function ShareButton({ rules, injectRules, selectedUrl }) {
window.open(url, "_blank");
} catch (err) {
alert.warning(i18n("error_got_some_wrong"));
console.log("[share rules]", err);
kissLog(err, "share rules");
}
};
@@ -731,7 +732,7 @@ function UserRules({ subRules }) {
try {
await rules.merge(JSON.parse(data));
} catch (err) {
console.log("[import rules]", err);
kissLog(err, "import rules");
}
};
@@ -864,7 +865,7 @@ function SubRulesItem({
await delSubRules(url);
await deleteDataCache(url);
} catch (err) {
console.log("[del subrules]", err);
kissLog(err, "del subrules");
}
};
@@ -877,7 +878,7 @@ function SubRulesItem({
}
await updateDataCache(url);
} catch (err) {
console.log("[sync sub rules]", err);
kissLog(err, "sync sub rules");
} finally {
setLoading(false);
}
@@ -956,7 +957,7 @@ function SubRulesEdit({ subList, addSub, updateDataCache }) {
setShowInput(false);
setInputText("");
} catch (err) {
console.log("[fetch rules]", err);
kissLog(err, "fetch rules");
setInputError(i18n("error_fetch_url"));
} finally {
setLoading(false);

View File

@@ -28,6 +28,7 @@ import { useShortcut } from "../../hooks/Shortcut";
import ShortcutInput from "./ShortcutInput";
import { useFab } from "../../hooks/Fab";
import { sendBgMsg } from "../../libs/msg";
import { kissLog } from "../../libs/log";
function ShortcutItem({ action, label }) {
const { shortcut, setShortcut } = useShortcut(action);
@@ -82,7 +83,7 @@ export default function Settings() {
caches.delete(CACHE_NAME);
alert.success(i18n("clear_success"));
} catch (err) {
console.log("[clear cache]", err);
kissLog(err, "clear cache");
}
};

View File

@@ -19,6 +19,7 @@ import { useAlert } from "../../hooks/Alert";
import SyncIcon from "@mui/icons-material/Sync";
import CircularProgress from "@mui/material/CircularProgress";
import { useSetting } from "../../hooks/Setting";
import { kissLog } from "../../libs/log";
export default function SyncSetting() {
const i18n = useI18n();
@@ -43,7 +44,7 @@ export default function SyncSetting() {
await reloadSetting();
alert.success(i18n("sync_success"));
} catch (err) {
console.log("[sync all]", err);
kissLog(err, "sync all");
alert.error(i18n("sync_failed"));
} finally {
setLoading(false);

View File

@@ -27,6 +27,7 @@ import {
import { sendIframeMsg } from "../../libs/iframe";
import { saveRule } from "../../libs/rules";
import { tryClearCaches } from "../../libs";
import { kissLog } from "../../libs/log";
export default function Popup({ setShowPopup, translator: tran }) {
const i18n = useI18n();
@@ -55,7 +56,7 @@ export default function Popup({ setShowPopup, translator: tran }) {
sendIframeMsg(MSG_TRANS_TOGGLE);
}
} catch (err) {
console.log("[toggle trans]", err);
kissLog(err, "toggle trans");
}
};
@@ -71,7 +72,7 @@ export default function Popup({ setShowPopup, translator: tran }) {
sendIframeMsg(MSG_TRANS_PUTRULE, { [name]: value });
}
} catch (err) {
console.log("[update rule]", err);
kissLog(err, "update rule");
}
};
@@ -93,7 +94,7 @@ export default function Popup({ setShowPopup, translator: tran }) {
saveRule(newRule);
}
} catch (err) {
console.log("[save rule]", err);
kissLog(err, "save rule");
}
};
@@ -108,7 +109,7 @@ export default function Popup({ setShowPopup, translator: tran }) {
setRule(res.data);
}
} catch (err) {
console.log("[query rule]", err);
kissLog(err, "query rule");
}
})();
}, [tran]);
@@ -132,7 +133,7 @@ export default function Popup({ setShowPopup, translator: tran }) {
}
setCommands(commands);
} catch (err) {
console.log("[query cmds]", err);
kissLog(err, "query cmds");
}
})();
}, [tran]);

View File

@@ -3,6 +3,7 @@ import FavoriteIcon from "@mui/icons-material/Favorite";
import FavoriteBorderIcon from "@mui/icons-material/FavoriteBorder";
import { useState } from "react";
import { useFavWords } from "../../hooks/FavWords";
import { kissLog } from "../../libs/log";
export default function FavBtn({ word }) {
const { favWords, toggleFav } = useFavWords();
@@ -13,7 +14,7 @@ export default function FavBtn({ word }) {
setLoading(true);
await toggleFav(word);
} catch (err) {
console.log("[set fav]", err);
kissLog(err, "set fav");
} finally {
setLoading(false);
}

View File

@@ -6,6 +6,7 @@ import { sleep, limitNumber } from "../../libs/utils";
import { isGm, isExt } from "../../libs/client";
import { MSG_OPEN_TRANBOX, DEFAULT_TRANBOX_SHORTCUT } from "../../config";
import { isMobile } from "../../libs/mobile";
import { kissLog } from "../../libs/log";
export default function Slection({
contextMenuType,
@@ -127,7 +128,7 @@ export default function Slection({
});
};
} catch (err) {
console.log("[registerMenuCommand]", err);
kissLog(err, "registerMenuCommand");
}
}, [handleTranbox, contextMenuType]);