var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
var __typeError = (msg) => {
  throw TypeError(msg);
};
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
var __runInitializers = (array, flags, self, value) => {
  for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
  return value;
};
var __decorateElement = (array, flags, name, decorators, target, extra) => {
  var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
  var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
  var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
  var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
    return __privateGet(this, extra);
  }, set [name](x) {
    return __privateSet(this, extra, x);
  } }, name));
  k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
  for (var i = decorators.length - 1; i >= 0; i--) {
    ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
    if (k) {
      ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
      if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
      if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
    }
    it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
    if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
    else if (typeof it !== "object" || it === null) __typeError("Object expected");
    else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
  }
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
};
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);

// src/core/logger/hooks.ts
import { SyncHook } from "tapable";
import { generateHooksAccess } from "@diplodoc/cli/lib/utils";
function hooks(name) {
  return {
    Info: new SyncHook(["message"], `${name}.Info`),
    Warn: new SyncHook(["message"], `${name}.Warn`),
    Error: new SyncHook(["message"], `${name}.Error`)
  };
}
var [getHooks, withHooks] = generateHooksAccess("Logger", hooks);

// src/core/logger/logger.ts
import { green, red, yellow } from "chalk";
import { pick } from "lodash";
var LogLevel = {
  INFO: "info",
  WARN: "warn",
  ERROR: "error"
};
var INFO = Symbol.for(LogLevel.INFO);
var WARN = Symbol.for(LogLevel.WARN);
var ERROR = Symbol.for(LogLevel.ERROR);
var Write = /* @__PURE__ */ Symbol("write");
function writer(logger, level) {
  const writer2 = function(...msgs) {
    writer2.count++;
    const message = msgs.join(" ");
    logger[Write](level, message);
    const hook = { info: "Info", warn: "Warn", error: "Error" }[level];
    getHooks(logger)[hook].call(message);
  };
  writer2.count = 0;
  return writer2;
}
var colors = {
  [LogLevel.INFO]: green,
  [LogLevel.WARN]: yellow,
  [LogLevel.ERROR]: red
};
var _a, _b, _c, _Logger_decorators, _init;
_Logger_decorators = [withHooks];
var Logger = class {
  constructor(options = {}, filters = []) {
    this[_c] = writer(this, LogLevel.INFO);
    this[_b] = writer(this, LogLevel.WARN);
    this[_a] = writer(this, LogLevel.ERROR);
    this.info = this.topic(LogLevel.INFO, "INFO");
    this.warn = this.topic(LogLevel.WARN, "WARN");
    this.error = this.topic(LogLevel.ERROR, "ERR");
    this.options = {
      colors: true,
      quiet: false
    };
    this.consumer = null;
    this.filters = void 0;
    this.filters = filters;
    this.setup(options);
    this.reset();
  }
  setup(options = {}) {
    this.options = Object.assign(this.options, pick(options, ["quiet"]));
    return this;
  }
  /**
   * Pipe local log channels to parent log channels.
   * This doesn't pipe topics processing.
   * So if child and parent has the same topic with name 'proc',
   * only local topic will be applied to message.
   * Message will be decorated by local topic and will be passed to parent as raw string.
   *
   * @param {LogConsumer} consumer - parent logger
   * @returns {Logger}
   */
  pipe(consumer) {
    if (this.consumer && this.consumer !== consumer) {
      throw new Error("This log already piped to another consumer.");
    }
    this.consumer = consumer;
    return this;
  }
  subscribe(subject) {
    subject.subscribe((record) => {
      this[Symbol.for(record.level)](record.message);
    });
  }
  /**
   * Defines new write decorator to one of defined log channeld.
   * Each decorator adds colored prefix to messages and apply preconfigured filters.
   *
   * @param {LogLevels} level
   * @param {string} prefix - any bounded text prefix, which will be colored
   * @param {Color} [color] - prefix color
   * @returns new topic
   */
  topic(level, prefix, color) {
    const channel = Symbol.for(level);
    const _writer = this[channel];
    const _color = color || colors[level];
    const topic = (...messages) => {
      messages = messages.map(extractMessage);
      const message = this.filters.reduce((message2, filter) => {
        return filter(level, message2);
      }, messages.join(" "));
      if (!message) {
        return;
      }
      topic.count++;
      if (this.options.quiet && [INFO].includes(channel)) {
        return;
      }
      _writer((this.options.colors ? _color(prefix) : prefix) + " " + message);
    };
    topic.count = 0;
    return topic;
  }
  reset() {
    for (const level of Object.values(LogLevel)) {
      this[Symbol.for(level)].count = 0;
    }
    return this;
  }
  [(_c = INFO, _b = WARN, _a = ERROR, Write)](level, message) {
    if (this.consumer) {
      this.consumer[Symbol.for(level)](message);
    } else {
      console[level](message);
    }
  }
};
_init = __decoratorStart(null);
Logger = __decorateElement(_init, 0, "Logger", _Logger_decorators, Logger);
__runInitializers(_init, 1, Logger);
function extractMessage(error) {
  if (!error) {
    return "";
  }
  if (typeof error === "string") {
    return error;
  }
  if (typeof error === "object" && "message" in error) {
    return String(error.message);
  }
  return String(error);
}
function stats(logger) {
  return {
    [LogLevel.INFO]: logger[INFO].count,
    [LogLevel.WARN]: logger[WARN].count,
    [LogLevel.ERROR]: logger[ERROR].count
  };
}
export {
  LogLevel,
  Logger,
  getHooks,
  stats
};
//# sourceMappingURL=index.mjs.map
