headplane/app/utils/log.ts

30 lines
767 B
TypeScript
Raw Normal View History

export default {
info: (category: string, message: string, ...args: unknown[]) => {
2024-12-31 10:30:14 +05:30
defaultLog('INFO', category, message, ...args);
},
warn: (category: string, message: string, ...args: unknown[]) => {
2024-12-31 10:30:14 +05:30
defaultLog('WARN', category, message, ...args);
},
error: (category: string, message: string, ...args: unknown[]) => {
2024-12-31 10:30:14 +05:30
defaultLog('ERRO', category, message, ...args);
},
debug: (category: string, message: string, ...args: unknown[]) => {
if (process.env.DEBUG === 'true') {
2024-12-31 10:30:14 +05:30
defaultLog('DEBG', category, message, ...args);
}
2024-12-31 10:30:14 +05:30
},
};
function defaultLog(
level: string,
category: string,
message: string,
...args: unknown[]
) {
2024-12-31 10:30:14 +05:30
const date = new Date().toISOString();
console.log(`${date} (${level}) [${category}] ${message}`, ...args);
}