This commit is contained in:
Flummi
2020-04-02 04:35:28 +02:00
parent 5ff96cdf5e
commit d39deeb038
100 changed files with 34498 additions and 1100 deletions

15
src/inc/log.mjs Normal file
View File

@@ -0,0 +1,15 @@
import fs from "fs";
const logger = ["debug", "info", "error"];
const logfiles = logger.reduce((a, b) => ({...a, [b]: fs.createWriteStream(`./logs/${~~(Date.now() / 1000)}_${b}.log`)}), {});
export default new Proxy({}, {
get: (_, prop) => (msg, timestamp = new Date().toLocaleString()) =>
logger.includes(prop) &&
logfiles[prop].write(JSON.stringify({
level: prop,
message: msg,
timestamp: timestamp
}) + "\n") &&
console.log(timestamp, prop, msg)
});