Update logger class
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import fs from "fs/promises";
|
||||
import type { AxiosError } from "axios";
|
||||
|
||||
type LogType = {
|
||||
title: string;
|
||||
@@ -47,11 +48,12 @@ class Logger {
|
||||
break;
|
||||
}
|
||||
|
||||
markdownContent += `# ${icon} ${log.title} \n`;
|
||||
markdownContent += `## ${[year, month, day].join("-")} ${hour}:${minutes}:${seconds} \n`;
|
||||
markdownContent += `## ${icon} ${log.title} \n`;
|
||||
// markdownContent += `## ${[year, month, day].join("-")} ${hour}:${minutes}:${seconds} \n`;
|
||||
markdownContent += `## ${hour} : ${minutes} : ${seconds} \n`;
|
||||
|
||||
if (log.message) {
|
||||
markdownContent += `**Message:** ${log.message}\n`;
|
||||
markdownContent += `**Message:**\n ${log.message}\n\n`;
|
||||
}
|
||||
if (log.details) {
|
||||
markdownContent += `**Details:**\n\n\`\`\`json\n${JSON.stringify(log.details, null, 2)}\n\`\`\`\n\n`;
|
||||
@@ -72,6 +74,23 @@ class Logger {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static async axiosErrorLog(error: any) {
|
||||
|
||||
const logData : LogType = {
|
||||
title : error?.message,
|
||||
message : `${error?.config?.method?.toUpperCase()} ${error?.config?.url}`,
|
||||
details : error,
|
||||
}
|
||||
|
||||
const formattedLog = this.formatToMarkdown(logData);
|
||||
|
||||
try {
|
||||
await fs.appendFile(".logs/log.md", formattedLog);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Logger;
|
||||
Reference in New Issue
Block a user