|
@@ -0,0 +1,67 @@
|
|
|
|
+import path from "path";
|
|
|
|
+
|
|
|
|
+/* 日期格式化 */
|
|
|
|
+export const dateFormat = (
|
|
|
|
+ date: any,
|
|
|
|
+ fmt = "yyyy-MM-dd hh:mm:ss",
|
|
|
|
+ isDefault = "-"
|
|
|
|
+) => {
|
|
|
|
+ if (date.toString().length === 10) {
|
|
|
|
+ date *= 1000;
|
|
|
|
+ }
|
|
|
|
+ date = new Date(date);
|
|
|
|
+
|
|
|
|
+ if (date.valueOf() < 1) {
|
|
|
|
+ return isDefault;
|
|
|
|
+ }
|
|
|
|
+ const o: any = {
|
|
|
|
+ "M+": date.getMonth() + 1, // 月份
|
|
|
|
+ "d+": date.getDate(), // 日
|
|
|
|
+ "h+": date.getHours(), // 小时
|
|
|
|
+ "m+": date.getMinutes(), // 分
|
|
|
|
+ "s+": date.getSeconds(), // 秒
|
|
|
|
+ "q+": Math.floor((date.getMonth() + 3) / 3), // 季度
|
|
|
|
+ S: date.getMilliseconds(), // 毫秒
|
|
|
|
+ };
|
|
|
|
+ if (/(y+)/.test(fmt)) {
|
|
|
|
+ fmt = fmt.replace(
|
|
|
|
+ RegExp.$1,
|
|
|
|
+ `${date.getFullYear()}`.substr(4 - RegExp.$1.length)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ for (const k in o) {
|
|
|
|
+ if (new RegExp(`(${k})`).test(fmt)) {
|
|
|
|
+ fmt = fmt.replace(
|
|
|
|
+ RegExp.$1,
|
|
|
|
+ RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return fmt;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const zlog = require("electron-log");
|
|
|
|
+const filepath: string = process.env.PORTABLE_EXECUTABLE_DIR || "";
|
|
|
|
+const nowdate = Date.now();
|
|
|
|
+const nowdate_str = dateFormat(nowdate, "yyyy-MM-dd");
|
|
|
|
+const filename = "download_" + nowdate_str + ".log";
|
|
|
|
+zlog.transports.file.resolvePath = () => path.join(filepath, filename);
|
|
|
|
+zlog.transports.file.level = true;
|
|
|
|
+zlog.transports.console.level = false;
|
|
|
|
+
|
|
|
|
+export async function errorLogger(student: any, imgUrl: string, error: any) {
|
|
|
|
+ let str = "download - 图片下载发生错误:\n";
|
|
|
|
+ str += ` 名称:${student.name};\n`;
|
|
|
|
+ str += ` 学号:${student.studentCode};\n`;
|
|
|
|
+ str += ` 科目:${student.subjectName};\n`;
|
|
|
|
+ str += ` 图片地址:${imgUrl};\n`;
|
|
|
|
+ str += ` [ ${error.toString()} ]\n`;
|
|
|
|
+ zlog.error(str);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export async function errorLogger2(imgUrl: string, error: any) {
|
|
|
|
+ let str = "download - 图片下载发生错误:\n";
|
|
|
|
+ str += ` 签到表图片:${imgUrl};\n`;
|
|
|
|
+ str += ` [ ${error.toString()} ]\n`;
|
|
|
|
+ zlog.error(str);
|
|
|
|
+}
|