next-with-linaria
Version:
Linaria support for Next.js App Router
66 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.Logger = void 0;
exports.createLogger = createLogger;
const LOG_LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
const COLORS = {
reset: '\x1b[0m',
debug: '\x1b[36m',
info: '\x1b[32m',
warn: '\x1b[33m',
error: '\x1b[31m',
bold: '\x1b[1m',
};
class Logger {
constructor(options = {}) {
this.prefix = options.prefix || 'next-with-linaria';
this.enableColors = options.enableColors !== false;
this.minLevel = options.minLevel || 'info';
}
shouldLog(level) {
return LOG_LEVELS[level] >= LOG_LEVELS[this.minLevel];
}
format(level, message) {
if (!this.enableColors) {
return `[${this.prefix}] ${level.toUpperCase()}: ${message}`;
}
const color = COLORS[level];
return `${color}[${this.prefix}]${COLORS.reset} ${COLORS.bold}${color}${level.toUpperCase()}:${COLORS.reset} ${message}`;
}
debug(message, ...args) {
if (!this.shouldLog('debug'))
return;
console.log(this.format('debug', message), ...args);
}
info(message, ...args) {
if (!this.shouldLog('info'))
return;
console.log(this.format('info', message), ...args);
}
warn(message, ...args) {
if (!this.shouldLog('warn'))
return;
console.warn(this.format('warn', message), ...args);
}
error(message, ...args) {
if (!this.shouldLog('error'))
return;
console.error(this.format('error', message), ...args);
}
colorize(message, color = 'info') {
if (!this.enableColors)
return message;
return `${COLORS[color]}${message}${COLORS.reset}`;
}
}
exports.Logger = Logger;
exports.logger = new Logger();
function createLogger(options) {
return new Logger(options);
}
//# sourceMappingURL=logger.js.map