advance
This commit is contained in:
21
lib/logger.ts
Normal file
21
lib/logger.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
const getTimestamp = () => new Date().toISOString();
|
||||
|
||||
export const logger = {
|
||||
info: (message: string, ...args: unknown[]) => {
|
||||
console.log(`[INFO] [${getTimestamp()}] ${message}`, ...args);
|
||||
},
|
||||
warn: (message: string, ...args: unknown[]) => {
|
||||
console.warn(`[WARN] [${getTimestamp()}] ${message}`, ...args);
|
||||
},
|
||||
error: (message: string, error?: unknown) => {
|
||||
console.error(`[ERROR] [${getTimestamp()}] ${message}`, error);
|
||||
if (error instanceof Error) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
},
|
||||
debug: (message: string, ...args: unknown[]) => {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.debug(`[DEBUG] [${getTimestamp()}] ${message}`, ...args);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user