wn-ts-node
Version:
Wordnet interface library - TypeScript port
73 lines (72 loc) • 2.16 kB
JavaScript
var i;
(function(e) {
e[e.SILENT = 0] = "SILENT", e[e.ERROR = 1] = "ERROR", e[e.WARN = 2] = "WARN", e[e.INFO = 3] = "INFO", e[e.DEBUG = 4] = "DEBUG", e[e.VERBOSE = 5] = "VERBOSE";
})(i || (i = {}));
class n {
level = i.INFO;
prefix = "";
constructor(s, o) {
s !== void 0 && (this.level = s), o !== void 0 && (this.prefix = o);
}
setLevel(s) {
this.level = s;
}
setPrefix(s) {
this.prefix = s;
}
shouldLog(s) {
return s <= this.level;
}
formatMessage(s, o) {
return this.prefix ? `${this.prefix} ${s}: ${o}` : `${s}: ${o}`;
}
error(s, ...o) {
this.shouldLog(i.ERROR) && console.error(this.formatMessage("ERROR", s), ...o);
}
warn(s, ...o) {
this.shouldLog(i.WARN) && console.warn(this.formatMessage("WARN", s), ...o);
}
info(s, ...o) {
this.shouldLog(i.INFO) && console.log(this.formatMessage("INFO", s), ...o);
}
debug(s, ...o) {
this.shouldLog(i.DEBUG) && console.log(this.formatMessage("DEBUG", s), ...o);
}
verbose(s, ...o) {
this.shouldLog(i.VERBOSE) && console.log(this.formatMessage("VERBOSE", s), ...o);
}
// Convenience methods for common patterns
success(s, ...o) {
this.shouldLog(i.INFO) && console.log(`✅ ${s}`, ...o);
}
progress(s, ...o) {
this.shouldLog(i.INFO) && console.log(`📊 ${s}`, ...o);
}
config(s, ...o) {
this.shouldLog(i.DEBUG) && console.log(`🔧 ${s}`, ...o);
}
data(s, ...o) {
this.shouldLog(i.DEBUG) && console.log(`📝 ${s}`, ...o);
}
synset(s, ...o) {
this.shouldLog(i.DEBUG) && console.log(`📚 ${s}`, ...o);
}
download(s, ...o) {
this.shouldLog(i.INFO) && console.log(`⬇️ ${s}`, ...o);
}
extract(s, ...o) {
this.shouldLog(i.INFO) && console.log(`📦 ${s}`, ...o);
}
insert(s, ...o) {
this.shouldLog(i.DEBUG) && console.log(`💾 ${s}`, ...o);
}
}
const t = new n(), r = typeof process < "u" && process.versions && process.versions.node;
r && process.env.NODE_ENV === "test" && t.setLevel(i.ERROR);
if (r && process.env.WN_TS_LOG_LEVEL) {
const e = parseInt(process.env.WN_TS_LOG_LEVEL);
!isNaN(e) && e >= 0 && e <= 5 && t.setLevel(e);
}
export {
t as l
};