1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/wtto00-aliyun-oss-log-analysis

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
util.js 1.2 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
wangtaotao Отправлено 5 лет назад f09d772
/* eslint-disable no-console */
const fs = require("fs");
const path = require("path");
const { app } = require("electron");
const logPath = app.getPath("logs");
const configPath = path.join(app.getPath("userData"), "config.json");
const log = {
error: (data = "") => {
try {
if (typeof data !== "string") {
return;
}
const date = new Date();
const text =
[date.getFullYear(), date.getMonth(), date.getDate()].join("-") +
" " +
[date.getHours(), date.getMinutes(), date.getSeconds()].join(":") +
" ";
fs.appendFile(
path.join(logPath, "error.log"),
text + data + "\n",
() => {}
);
} catch (error) {
console.error("log error:", error);
}
},
};
const getConfig = () => {
try {
const data = fs.readFileSync(configPath);
return JSON.parse(data) || {};
} catch (error) {
log.error(JSON.stringify(error));
return {};
}
};
const setConfig = (data = {}) => {
// console.log("configPath:", configPath);
try {
fs.writeFileSync(configPath, JSON.stringify(data));
} catch (error) {
log.error(JSON.stringify(error));
}
};
module.exports = {
log,
getConfig,
setConfig,
};

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/wtto00-aliyun-oss-log-analysis.git
git@gitlife.ru:oschina-mirror/wtto00-aliyun-oss-log-analysis.git
oschina-mirror
wtto00-aliyun-oss-log-analysis
wtto00-aliyun-oss-log-analysis
master