mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Reduced logging output
This commit is contained in:
parent
9ae7930141
commit
d6edfa15e1
2 changed files with 72 additions and 13 deletions
67
utils.js
Normal file
67
utils.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
module.exports = {
|
||||
ReadFile: ReadFile,
|
||||
WriteFile: WriteFile,
|
||||
writeFileAsync: WriteFileAsync,
|
||||
AppendToFile: AppendToFile,
|
||||
Beep: Beep,
|
||||
WriteBackup: WriteBackup
|
||||
};
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var logger = require('./logger.js');
|
||||
|
||||
const recievedFile = "stats/recieved";
|
||||
const publicFile = "public/data/public";
|
||||
const staticFile = "public/data/static";
|
||||
const manFile = "public/man.html";
|
||||
const logFile = "stats/logs";
|
||||
|
||||
function ReadFile(name) {
|
||||
return fs.readFileSync(name, "utf8");
|
||||
}
|
||||
|
||||
function WriteFile(content, path) {
|
||||
fs.writeFileSync(path, content);
|
||||
}
|
||||
|
||||
function WriteFileAsync(content, path) {
|
||||
fs.writeFile(path, content, function(err) {
|
||||
if (err) {
|
||||
logger.Log("[ERR ]: Error writing file: " + path + " (sync)", logger.GetColor("redbg"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function AppendToFile(data, file) {
|
||||
fs.appendFile(file, "\n" + data, function(err) {
|
||||
if (err)
|
||||
logger.Log("[ERR ]: Error writing log file: " + path + " (sync)", logger.GetColor("redbg"));
|
||||
});
|
||||
}
|
||||
|
||||
function Beep() {
|
||||
try {
|
||||
process.stdout.write('\x07');
|
||||
} catch (e) {
|
||||
console.log("error beepin");
|
||||
}
|
||||
}
|
||||
|
||||
function WriteBackup() {
|
||||
try {
|
||||
WriteFileAsync(ReadFile(recievedFile), 'public/backs/recieved_' + new Date().toString());
|
||||
//logger.Log('[SAVE]: New questions backup wrote');
|
||||
|
||||
} catch (e) {
|
||||
logger.Log("[ERR ]: Error backing up recieved file!", logger.GetColor("redbg"));
|
||||
console.log(e);
|
||||
}
|
||||
try {
|
||||
WriteFileAsync(ReadFile(publicFile), 'public/backs/public_' + new Date().toString());
|
||||
//logger.Log('[SAVE]: Public questions backup wrote');
|
||||
} catch (e) {
|
||||
logger.Log("[ERR ]: Error backing up public file!", logger.GetColor("redbg"), true);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue