Base structure #2
This commit is contained in:
		| @@ -1,24 +1,25 @@ | ||||
| /* eslint-disable prefer-rest-params */ | ||||
| /** | ||||
|  * This module swaps the default console outputs to own functions and adds a timestamp to each message | ||||
|  * (c) 2022 AstroGD | ||||
|  */ | ||||
|  | ||||
|  import path from "path"; | ||||
|  import fs from "fs-extra"; | ||||
|   | ||||
|  export default function() { | ||||
|      fs.ensureDirSync(path.join(__dirname, "../data/log/")); | ||||
|      fs.ensureDirSync(path.join(__dirname, "../../data/logs/")); | ||||
|   | ||||
|      const callDate = new Date(); | ||||
|      const logFileName = `${callDate.getUTCFullYear()}-${`0${callDate.getUTCMonth() + 1}`.slice(-2)}-${`0${callDate.getUTCDate()}`.slice(-2)}-${`0${callDate.getUTCHours()}`.slice(-2)}-${`0${callDate.getUTCMinutes()}`.slice(-2)}-${`0${callDate.getUTCSeconds()}`.slice(-2)}-${`00${callDate.getUTCMilliseconds()}`.slice(-3)}.log`; | ||||
|      const logFile = fs.createWriteStream(path.join(__dirname, `../data/log/${logFileName}`)); | ||||
|      const logFile = fs.createWriteStream(path.join(__dirname, `../../data/logs/${logFileName}`)); | ||||
|      const out = new console.Console(process.stdout, process.stderr, true); | ||||
|      const logConsole = new console.Console(logFile); | ||||
|   | ||||
|      function log() { | ||||
|          const now = new Date(); | ||||
|          const Prepend = `[i] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] `; | ||||
|          arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`; | ||||
|          arguments[0] = `${Prepend}${arguments[0]?.toString().normalize()}`; | ||||
|   | ||||
|          for (let i = 0; i < arguments.length; i++) { | ||||
|              arguments[i] = arguments[i].split("\n").join(`\n${new Array(31).join(" ")}`); | ||||
| @@ -31,10 +32,10 @@ | ||||
|      function warn() { | ||||
|          const now = new Date(); | ||||
|          const Prepend = `[W] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] `; | ||||
|          arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`; | ||||
|          arguments[0] = `${Prepend}${arguments[0]?.toString().normalize()}`; | ||||
|   | ||||
|          for (let i = 0; i < arguments.length; i++) { | ||||
|              const argument = arguments[i].toString().normalize(); | ||||
|              const argument = arguments[i]?.toString().normalize(); | ||||
|              arguments[i] = argument.split("\n").join(`\n${new Array(31).join(" ")}`); | ||||
|          } | ||||
|   | ||||
| @@ -45,10 +46,10 @@ | ||||
|      function error() { | ||||
|          const now = new Date(); | ||||
|          const Prepend = `==== [ERROR] [${now.getUTCFullYear()}-${`0${now.getUTCMonth() + 1}`.slice(-2)}-${`0${now.getUTCDate()}`.slice(-2)} ${`0${now.getUTCHours()}`.slice(-2)}:${`0${now.getUTCMinutes()}`.slice(-2)}:${`0${now.getUTCSeconds()}`.slice(-2)}.${`00${now.getUTCMilliseconds()}`.slice(-3)}] ====\n`; | ||||
|          arguments[0] = `${Prepend}${arguments[0].toString().normalize()}`; | ||||
|          arguments[0] = `${Prepend}${arguments[0]?.toString().normalize()}`; | ||||
|   | ||||
|          for (let i = 0; i < arguments.length; i++) { | ||||
|              arguments[i] = arguments[i].toString().normalize(); | ||||
|              arguments[i] = arguments[i]?.toString().normalize(); | ||||
|          } | ||||
|   | ||||
|          out.error(...arguments); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user