Feat: server-infoエンドポイント / Fix: logger.tsを追跡対象に / Feat: lynqchat-jsを利用可能に / Fix: lynqchat-jsに不足していたエンドポイントを追加
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
import { appendFileSync } from "node:fs";
|
||||
import { EOL } from "node:os";
|
||||
|
||||
const createLog = (
|
||||
nativeLogger: (...args: any[]) => void,
|
||||
type: string,
|
||||
...args: any[]
|
||||
) => {
|
||||
if (args[0] instanceof Array) {
|
||||
args = args[0];
|
||||
}
|
||||
|
||||
const content = `${new Date().toLocaleString()} [${type}] ${args.join("\n").replaceAll("\n", "\n ")}`;
|
||||
|
||||
nativeLogger(content);
|
||||
|
||||
try {
|
||||
appendFileSync(
|
||||
`${import.meta.dirname}/../../../../.log/system.log`,
|
||||
`${content.toString().replace(/\x1B\[[0-9;]*m/g, '')}${EOL}`
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`${new Date().toLocaleString()} Logger: Failed to write to file.`);
|
||||
}
|
||||
}
|
||||
|
||||
const logger = {
|
||||
log: (...args: any[]) => createLog(console.log, "LOG", args),
|
||||
info: (...args: any[]) => createLog(console.info, "INFO", args),
|
||||
error: (...args: any[]) => createLog(console.error, "ERROR", args),
|
||||
warn: (...args: any[]) => createLog(console.warn, "WARN", args),
|
||||
}
|
||||
|
||||
export default logger;
|
||||
Reference in New Issue
Block a user