mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2025-12-06 08:04:06 +00:00
removed log location detail
This commit is contained in:
parent
e6bff5a472
commit
04e1ba3804
@ -1,9 +1,7 @@
|
||||
// TODO: rate limit module is busted (CJS types), do something for rate limiting
|
||||
import axios, { type AxiosInstance } from "axios";
|
||||
import { baseAPIURL, accountsAPIURL } from "../constants.ts";
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
const authInstance: AxiosInstance = axios.create({
|
||||
baseURL: accountsAPIURL,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { axiosInstance } from "./axios.ts";
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
|
||||
import { type AxiosResponse, type AxiosRequestConfig } from "axios";
|
||||
import type {
|
||||
@ -14,7 +13,7 @@ import type {
|
||||
Res,
|
||||
} from "spotify_manager/index.d.ts";
|
||||
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
const logPrefix = "Spotify API: ";
|
||||
enum allowedMethods {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { createClient } from "redis";
|
||||
|
||||
import { sleep } from "../utils/flake.ts";
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
if (!process.env["REDIS_URI"])
|
||||
throw new TypeError("Redis connection URI not defined");
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import type { SequelizeOptions } from "sequelize-typescript";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
type ConnConfigs = Record<string, SequelizeOptions>;
|
||||
|
||||
|
||||
@ -11,8 +11,7 @@ import type { RequestHandler } from "express";
|
||||
|
||||
import { generateRandString } from "../utils/generateRandString.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
/**
|
||||
* Stateful redirect to Spotify login with credentials
|
||||
|
||||
@ -30,8 +30,7 @@ import { redisClient } from "../config/redis.ts";
|
||||
import Playlists from "../models/playlists.ts";
|
||||
import Links from "../models/links.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
/**
|
||||
* Sync user's Spotify data
|
||||
|
||||
@ -9,8 +9,7 @@ import type {
|
||||
SimplifiedPlaylistObject,
|
||||
} from "spotify_manager/index.d.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
/**
|
||||
* Get user's playlists
|
||||
|
||||
5
index.ts
5
index.ts
@ -22,8 +22,7 @@ import authRoutes from "./routes/auth.ts";
|
||||
import playlistRoutes from "./routes/playlists.ts";
|
||||
import operationRoutes from "./routes/operations.ts";
|
||||
|
||||
import curriedLogger from "./utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "./utils/logger.ts";
|
||||
|
||||
const app = express();
|
||||
|
||||
@ -131,7 +130,7 @@ const cleanupFunc = (signal?: string) => {
|
||||
|
||||
Promise.allSettled([
|
||||
redisClient.disconnect,
|
||||
seqConn.close(),
|
||||
seqConn.close,
|
||||
promisify(server.close),
|
||||
]).then(() => {
|
||||
logger.info("Cleaned up, exiting.");
|
||||
|
||||
@ -3,8 +3,7 @@ import type { RequestHandler } from "express";
|
||||
|
||||
import { sessionName } from "../constants.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
export const isAuthenticated: RequestHandler = (req, res, next) => {
|
||||
if (req.session.accessToken) {
|
||||
|
||||
@ -6,8 +6,7 @@ import seqConfig from "../config/sequelize.ts";
|
||||
import links from "./links.ts";
|
||||
import playlists from "./playlists.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
if (!process.env["NODE_ENV"])
|
||||
throw new TypeError("Node environment not defined");
|
||||
|
||||
@ -2,65 +2,57 @@ import path from "path";
|
||||
|
||||
import { createLogger, transports, config, format, type Logger } from "winston";
|
||||
|
||||
const { combine, label, timestamp, printf, errors } = format;
|
||||
const { combine, timestamp, printf, errors } = format;
|
||||
|
||||
const getLabel = (callingModuleName: string) => {
|
||||
if (!callingModuleName) return "repl";
|
||||
const parts = callingModuleName.split(path.sep);
|
||||
return path.join(
|
||||
parts[parts.length - 2] ?? "",
|
||||
parts[parts.length - 1] ?? ""
|
||||
);
|
||||
};
|
||||
|
||||
const allowedErrorKeys = ["name", "code", "message", "stack"];
|
||||
|
||||
const metaFormat = (meta: Record<string, unknown>) => {
|
||||
const metaFormat = (meta: object) => {
|
||||
const disallowedKeySets = [{ type: Error, keys: ["stack"] }];
|
||||
if (Object.keys(meta).length > 0)
|
||||
return "\n" + JSON.stringify(meta, null, "\t");
|
||||
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 "";
|
||||
};
|
||||
|
||||
const logFormat = printf(({ level, message, label, timestamp, ...meta }) => {
|
||||
if (meta["error"]) {
|
||||
const sanitizedError = Object.fromEntries(
|
||||
Object.entries(meta["error"]).filter(([key]) =>
|
||||
allowedErrorKeys.includes(key)
|
||||
)
|
||||
);
|
||||
|
||||
const { stack, ...rest } = sanitizedError;
|
||||
const errorObj: Error = meta["error"] as Error;
|
||||
if (errorObj) {
|
||||
return (
|
||||
`${timestamp} [${label}] ${level}: ${message}${metaFormat(rest)}\n` +
|
||||
`${stack ?? ""}`
|
||||
`${timestamp} [${level.toUpperCase()}]: ${message}${metaFormat(
|
||||
errorObj
|
||||
)}\n` + `${errorObj["stack"] ?? ""}`
|
||||
);
|
||||
}
|
||||
return `${timestamp} [${label}] ${level}: ${message}${metaFormat(meta)}`;
|
||||
return `${timestamp} [${level.toUpperCase()}]: ${message}${metaFormat(meta)}`;
|
||||
});
|
||||
|
||||
const loggerCache = new Map<string, ReturnType<typeof createLogger>>();
|
||||
|
||||
const curriedLogger = (callingModuleName: string): Logger => {
|
||||
if (loggerCache.has(callingModuleName)) {
|
||||
return loggerCache.get(callingModuleName)!;
|
||||
}
|
||||
const winstonLogger = createLogger({
|
||||
const winstonLogger: Logger = createLogger({
|
||||
levels: config.npm.levels,
|
||||
format: combine(
|
||||
errors({ stack: true }),
|
||||
label({ label: getLabel(callingModuleName) }),
|
||||
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
||||
logFormat
|
||||
),
|
||||
transports: [
|
||||
new transports.Console({ level: "info" }),
|
||||
new transports.File({
|
||||
filename: import.meta.dirname + "/../logs/debug.log",
|
||||
filename: path.join(import.meta.dirname, "..", "logs", "debug.log"),
|
||||
level: "debug",
|
||||
maxsize: 10485760,
|
||||
}),
|
||||
new transports.File({
|
||||
filename: import.meta.dirname + "/../logs/error.log",
|
||||
filename: path.join(import.meta.dirname, "..", "logs", "error.log"),
|
||||
level: "error",
|
||||
maxsize: 1048576,
|
||||
}),
|
||||
@ -69,8 +61,5 @@ const curriedLogger = (callingModuleName: string): Logger => {
|
||||
winstonLogger.on("error", (error) =>
|
||||
winstonLogger.error("Error inside logger", { error })
|
||||
);
|
||||
loggerCache.set(callingModuleName, winstonLogger);
|
||||
return winstonLogger;
|
||||
};
|
||||
|
||||
export default curriedLogger;
|
||||
export default winstonLogger;
|
||||
|
||||
@ -4,8 +4,7 @@ import type { RequestHandler } from "express";
|
||||
|
||||
import { getNestedValuesString } from "../utils/jsonTransformer.ts";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
import logger from "../utils/logger.ts";
|
||||
|
||||
/** Refer: https://stackoverflow.com/questions/58848625/access-messages-in-express-validator */
|
||||
export const validate: RequestHandler = (req, res, next) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user