OverviewFilesCommitsIssuesDocsReleasesPeers

keet-deobfuscated / @holepunchto / keet-core / lib / core / log.js

52 lines · javascript ref:
const e = require("bare-file-logger"),
  i = require("bare-system-logger"),
  t = { debug: 0, info: 1, warn: 2, error: 3 }
class s {
  constructor({
    dev: s = !1,
    verbose: r = !1,
    logFile: o,
    logLevel: l = "info",
    logFileMaxSize: h,
  } = {}) {
    ;((this._muted = !1),
      (this._dev = s),
      (this.verbose = r),
      (this.level = t[l] ?? t.info),
      (this._system = new i()),
      (this._file = o ? new e(o, { maxSize: h || 1e8 }) : null))
  }
  mute() {
    this._muted = !0
  }
  unmute() {
    this._muted = !1
  }
  debug(...e) {
    this._write("debug", ...e)
  }
  verboseDebug(...e) {
    this.verbose && this._write("debug", ...e)
  }
  verboseInfo(...e) {
    this.verbose && this._write("info", ...e)
  }
  info(...e) {
    this._write("info", ...e)
  }
  warn(...e) {
    this._write("warn", ...e)
  }
  error(...e) {
    this._write("error", ...e)
  }
  _write(e, ...i) {
    this._muted ||
      t[e] < this.level ||
      (this._dev && this.level === t.debug && (console[e] || console.log)(...i),
      this._system[e](...i),
      this._file && this._file[e](...i))
  }
}
module.exports = s