mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 14:14:06 +00:00
error handling robustness, logger corrections, better playlist-editable checking
This commit is contained in:
@@ -2,36 +2,22 @@ import path from "path";
|
||||
|
||||
import { createLogger, transports, config, format, type Logger } from "winston";
|
||||
|
||||
const { combine, timestamp, printf, errors } = format;
|
||||
const { combine, timestamp, printf } = format;
|
||||
|
||||
const metaFormat = (meta: object) => {
|
||||
const disallowedKeySets = [{ type: Error, keys: ["stack"] }];
|
||||
if (Object.keys(meta).length > 0)
|
||||
return (
|
||||
"\n" +
|
||||
JSON.stringify(
|
||||
meta,
|
||||
Object.getOwnPropertyNames(meta).filter((key) => {
|
||||
for (const pair of disallowedKeySets) {
|
||||
if (meta instanceof pair.type) {
|
||||
return !pair.keys.includes(key);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
"\t"
|
||||
)
|
||||
);
|
||||
return "\n" + JSON.stringify(meta, null, "\t");
|
||||
return "";
|
||||
};
|
||||
|
||||
const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
|
||||
const logFormat = printf(({ level, message, timestamp, stack, ...meta }) => {
|
||||
const errorObj: Error = meta["error"] as Error;
|
||||
if (errorObj) {
|
||||
const stackStr = errorObj["stack"];
|
||||
return (
|
||||
`${timestamp} [${level.toUpperCase()}]: ${message}` + // line 1
|
||||
`${metaFormat(errorObj)}\n` + // metadata
|
||||
`${errorObj["stack"] ?? ""}` // stack trace if any
|
||||
`${stackStr}` // stack trace if any
|
||||
);
|
||||
}
|
||||
return `${timestamp} [${level.toUpperCase()}]: ${message}${metaFormat(meta)}`;
|
||||
@@ -39,11 +25,7 @@ const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
|
||||
|
||||
const winstonLogger: Logger = createLogger({
|
||||
levels: config.npm.levels,
|
||||
format: combine(
|
||||
errors({ stack: true }),
|
||||
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
||||
logFormat
|
||||
),
|
||||
format: combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), logFormat),
|
||||
transports: [
|
||||
new transports.Console({ level: "info" }),
|
||||
new transports.File({
|
||||
@@ -58,7 +40,7 @@ const winstonLogger: Logger = createLogger({
|
||||
],
|
||||
});
|
||||
winstonLogger.on("error", (error) =>
|
||||
winstonLogger.error("Error inside logger", { error })
|
||||
console.error("Error inside logger", error)
|
||||
);
|
||||
winstonLogger.exceptions.handle(
|
||||
new transports.File({
|
||||
|
||||
Reference in New Issue
Block a user