prisma-cache-nosql
Version:
<div> <a href="https://www.npmjs.com/package/prisma-cache-nosql"> <img alt="npm" src="https://img.shields.io/npm/v/prisma-cache-nosql?logo=npm&logoColor=white"> </a> <a href="https://github.com/BearToCode/prisma-cache-nosql/blob/master/LICENSE"> <i
89 lines (86 loc) • 2.35 kB
JavaScript
import chalk from 'chalk';
const Purple = chalk.hex('#9900EF');
const Gray = chalk.hex('#333333');
const Green = chalk.hex('#57F2A5');
const Red = chalk.hex('#F93131');
const Orange = chalk.hex('#FDA12E');
const DarkGray = chalk.hex('#42454b');
class Logger {
logLevel;
_module;
constructor(logLevel = 'warn') {
this.logLevel = logLevel;
}
module(name) {
const logger = new Logger(this.logLevel);
logger._module = name;
return logger;
}
/**
* Log a debug message to stdout
* @param args The arguments to log
*/
debug(...args) {
if (this.logLevel === 'debug') {
this.write({
type: 'debug',
color: Purple,
args,
method: console.debug
});
}
}
/**
* Log a message to stdout
* @param message The message to log
*/
log(...args) {
if (this.logLevel === 'debug' || this.logLevel === 'log') {
this.write({
type: 'log',
color: Green,
args,
method: console.log
});
}
}
/**
* Log a warning to stderr
* @param message The message to log
*/
warn(...args) {
if (this.logLevel === 'debug' || this.logLevel === 'log' || this.logLevel === 'warn') {
this.write({
type: 'warn',
color: Orange,
args,
method: console.warn
});
}
}
/**
* Log an error to stderr
* @param message The message to log
*/
error(...args) {
if (this.logLevel === 'debug' ||
this.logLevel === 'log' ||
this.logLevel === 'warn' ||
this.logLevel === 'error') {
this.write({
type: 'error',
color: Red,
args,
method: console.error
});
}
}
write({ type, color, args, method }) {
const prefix = this._module
? `${DarkGray('prisma-cache')} [${color.bold(type)}] ` + `<${Gray.italic(this._module)}>`
: `${DarkGray('prisma-cache')} [${color.bold(type)}]`;
method(prefix, ...args);
}
}
export { Logger };
//# sourceMappingURL=logger.js.map