vmagic
Version:
vMagic is a RESTFul framework for NodeJS applications.
41 lines (34 loc) • 1.41 kB
JavaScript
/*eslint no-console: ["error", { allow: ["log"] }] */
;
import chalk from "chalk";
class Logger {
warn(message) {
if (message instanceof Object && Object.keys(message).length > 0) {
console.log(`${chalk.green(new Date())} - ${chalk.yellow(JSON.stringify(message, null, 4))}`);
} else {
console.log(`${chalk.green(new Date())} - ${chalk.yellow(message)}`);
}
}
error(message) {
if (message instanceof Object && Object.keys(message).length > 0) {
console.log(`${chalk.green(new Date())} - ${chalk.red(JSON.stringify(message, null, 4))}`);
} else {
console.log(`${chalk.green(new Date())} - ${chalk.red(message)}`);
}
}
success(message) {
if (message instanceof Object && Object.keys(message).length > 0) {
console.log(`${chalk.green(new Date())} - ${chalk.green(JSON.stringify(message, null, 4))}`);
} else {
console.log(`${chalk.green(new Date())} - ${chalk.green(message)}`);
}
}
info(message) {
if (message instanceof Object && Object.keys(message).length > 0) {
console.log(`${chalk.green(new Date())} - ${chalk.cyan(JSON.stringify(message, null, 4))}`);
} else {
console.log(`${chalk.green(new Date())} - ${chalk.cyan(message)}`);
}
}
}
export default Logger;