feat(lib/log): doing a wrapper for the log

- Now the log will be unifed
This commit is contained in:
Raphael 2025-10-26 17:36:51 +01:00 committed by Raphaël
parent 690255b863
commit a9ac3eeec8

25
src/lib/log.ts Normal file
View file

@ -0,0 +1,25 @@
import chalk from 'chalk';
export const log = {
warn: (err: unknown, str?: string) => {
const error = err instanceof Error ? err : new Error(String(err));
console.warn(chalk.yellowBright(`⚠️ | ${str ? ` during ${str}` : ''}`));
console.warn(chalk.yellowBright(`\t${error.message}`));
console.warn(chalk.yellowBright(`\tStack:\n${error.stack ?? 'No stack available'}`));
},
error: (err: unknown, str?: string) => {
const error = err instanceof Error ? err : new Error(String(err));
console.error(chalk.redBright(`❌ | Error${str ? ` during ${str}` : ''}`));
console.error(chalk.redBright(`\t${error.message}`));
console.error(chalk.redBright(`\tStack:\n${error.stack ?? 'No stack available'}`));
},
success: (str: string) => {
console.log(chalk.greenBright(`✅ | ${str}`));
},
search: (name: string) => {
console.log(chalk.blueBright(`🔍 | Searching for ${name}`));
},
list: (name: string) => {
console.log(chalk.cyanBright(`\t✅ | ${name}`));
},
};