forked from txiuqw4/farmersworld-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
29 lines (25 loc) · 718 Bytes
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const orgLog = console.log;
const logs = [];
const MAX_LINES = 200;
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { TIMEZONE } = require("./config.json");
function nowAsString() {
return new Date()
.toLocaleString("en-US", {
timeZoneName: "short",
timeZone: TIMEZONE,
hour12: false,
})
.replace(
/(\d?\d\/\d?\d\/\d{4})\,\s(\d{1,2}\:\d{1,2}\:\d{1,2})\sGMT\+\d/,
"$2"
);
}
console.log = function (...oths) {
oths.unshift(`[${nowAsString()}]`);
orgLog(...oths);
logs.unshift(oths.join(" "));
if (logs.length > MAX_LINES) logs.pop();
};
export default logs;