//filename: ConsoleTransport.ts
import winston from 'winston';
import chalk from 'chalk';

export class ConsoleTransport extends winston.transports.Console {
  constructor(logLevel: string) {
    super({
      level: logLevel,
      format: winston.format.printf(({ level, message }) => {
        // Define the available colors in Chalk
        const colors: { [key: string]: keyof typeof chalk } = {
          info: 'green',
          warn: 'yellow',
          error: 'red',
          debug: 'cyan',
        };

        // Access chalk color function with proper type assertion
        const color = colors[level] || 'white'; // Default to 'white' if not found
        return `${(chalk[color] as chalk.ChalkFunction)(level)}: ${message}`;
      }),
    });
  }
}
