Fix hardcoded path for error.log and move errorLog() to UptimeKumaServer.errorLog()

This commit is contained in:
Louis Lam
2022-05-06 14:41:34 +08:00
parent 15820c6937
commit 429ad384d0
4 changed files with 34 additions and 34 deletions

View File

@@ -7,8 +7,6 @@ const { Resolver } = require("dns");
const childProcess = require("child_process");
const iconv = require("iconv-lite");
const chardet = require("chardet");
const fs = require("fs");
const nodeJsUtil = require("util");
const mqtt = require("mqtt");
// From ping-lite
@@ -206,7 +204,7 @@ exports.dnsResolve = function (hostname, resolverServer, rrtype) {
/**
* Retrieve value of setting based on key
* @param {string} key Key of setting to retrieve
* @returns {Promise<Object>} Object representation of setting
* @returns {Promise<any>} Value
*/
exports.setting = async function (key) {
let value = await R.getCell("SELECT `value` FROM setting WHERE `key` = ? ", [
@@ -524,29 +522,3 @@ exports.convertToUTF8 = (body) => {
const str = iconv.decode(body, guessEncoding);
return str.toString();
};
let logFile;
try {
logFile = fs.createWriteStream("./data/error.log", {
flags: "a"
});
} catch (_) { }
/**
* Write error to log file
* @param {any} error The error to write
* @param {boolean} outputToConsole Should the error also be output to console?
*/
exports.errorLog = (error, outputToConsole = true) => {
try {
if (logFile) {
const dateTime = R.isoDateTime();
logFile.write(`[${dateTime}] ` + nodeJsUtil.format(error) + "\n");
if (outputToConsole) {
console.error(error);
}
}
} catch (_) { }
};