node-logger-light
Version:
An advanced logging library for Node.js with support for different log levels, file logging, and external services integration.
25 lines (22 loc) • 764 B
text/typescript
//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}`;
}),
});
}
}