actual-moneymoney
Version:
An importer for syncing MoneyMoney accounts and transactions to Actual.
49 lines (48 loc) • 1.54 kB
JavaScript
import chalk from 'chalk';
export var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
LogLevel[LogLevel["WARN"] = 1] = "WARN";
LogLevel[LogLevel["INFO"] = 2] = "INFO";
LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
})(LogLevel || (LogLevel = {}));
class Logger {
constructor(logLevel = LogLevel.INFO) {
this.logLevel = LogLevel.INFO;
this.logLevel = logLevel;
}
setLogLevel(level) {
this.logLevel = level;
}
error(message, hint) {
this.log(LogLevel.ERROR, message, hint);
}
warn(message, hint) {
this.log(LogLevel.WARN, message, hint);
}
info(message, hint) {
this.log(LogLevel.INFO, message, hint);
}
debug(message, hint) {
this.log(LogLevel.DEBUG, message, hint);
}
log(level, message, hint) {
if (this.logLevel >= level) {
const prefix = `[${LogLevel[level].toUpperCase()}]`;
const chalkColor = {
[LogLevel.ERROR]: chalk.red,
[LogLevel.WARN]: chalk.yellow,
[LogLevel.INFO]: chalk.cyan,
[LogLevel.DEBUG]: chalk.gray,
}[level];
console.log(chalkColor(prefix), message);
if (hint) {
const arrayHint = Array.isArray(hint) ? hint : [hint];
for (const hint of arrayHint) {
console.log(chalk.gray(' '.repeat(prefix.length), '↳', hint));
}
}
}
}
}
export default Logger;