All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 20s
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
/**
|
|
* A simple logger service that wraps the console.
|
|
* This provides a centralized place to manage logging behavior,
|
|
* such as adding timestamps, log levels, or sending logs to a remote service.
|
|
*/
|
|
|
|
const getTimestamp = () => new Date().toISOString();
|
|
|
|
type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'DEBUG';
|
|
|
|
const log = (level: LogLevel, message: string, ...args: any[]) => {
|
|
const timestamp = getTimestamp();
|
|
// We construct the log message with a timestamp and level for better context.
|
|
const logMessage = `[${timestamp}] [${level}] ${message}`;
|
|
|
|
switch (level) {
|
|
case 'INFO':
|
|
console.log(logMessage, ...args);
|
|
break;
|
|
case 'WARN':
|
|
console.warn(logMessage, ...args);
|
|
break;
|
|
case 'ERROR':
|
|
console.error(logMessage, ...args);
|
|
break;
|
|
case 'DEBUG':
|
|
// For now, we can show debug logs in development. This could be controlled by an environment variable.
|
|
console.debug(logMessage, ...args);
|
|
break;
|
|
}
|
|
};
|
|
|
|
// Export the logger object for use throughout the application.
|
|
export const logger = {
|
|
info: (message: string, ...args: any[]) => log('INFO', message, ...args),
|
|
warn: (message: string, ...args: any[]) => log('WARN', message, ...args),
|
|
error: (message: string, ...args: any[]) => log('ERROR', message, ...args),
|
|
debug: (message: string, ...args: any[]) => log('DEBUG', message, ...args),
|
|
}; |