"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.defaultLogger = void 0;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/FiberId/operations/threadName"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/definition"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/List/definition"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/LogSpan/operations/render"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/ImmutableMap/size"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * @tsplus static ets/Logger/Ops default
 */
const defaultLogger = {
  apply: (trace, fiberId, logLevel, message, cause0, context, spans, annotations) => {
    const cause = cause0();
    const now = new Date();
    const nowMillis = now.getTime();
    let output = [`timestamp=${now.toISOString()}`, ` level=${logLevel.label}`, ` thread=#${tsplus_module_1.threadName(fiberId)}`, ` message="${message()}"`].join("");

    if (cause != null && cause != tsplus_module_2.empty) {// TODO(Mike/Max): implement once tracing is complete
      // output = output + ` cause="${cause.prettyPrint()}"`
    }

    if (tsplus_module_3.length(spans) > 0) {
      output = output + " ";
      let first = true;

      for (const span of spans) {
        if (first) {
          first = false;
        } else {
          output = output + " ";
        }

        output = output + tsplus_module_4.render_(span, nowMillis);
      }
    }

    if (trace._tag === "SourceLocation") {
      const location = `${trace.fileName}:${trace.lineNumber}:${trace.columnNumber}`;
      output = output + " location=";
      output = appendQuoted(location, output);
    }

    if (tsplus_module_5.size(annotations) > 0) {
      output = output + " ";
      let first = true;

      for (const {
        tuple: [key, value]
      } of annotations) {
        if (first) {
          first = false;
        } else {
          output = output + " ";
        }

        output = appendQuoted(key, output);
        output = output + "=";
        output = appendQuoted(value, output);
      }
    }

    return output;
  }
};
exports.defaultLogger = defaultLogger;

function appendQuoted(label, output) {
  if (label.indexOf(" ") < 0) {
    return output + label;
  } else {
    return output + `"${label}"`;
  }
}
//# sourceMappingURL=default.js.map