import * as tsplus_module_1 from "@effect/core/io/FiberId/operations/threadName";
import * as tsplus_module_2 from "@effect/core/io/Cause/definition";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/List/definition";
import * as tsplus_module_4 from "@effect/core/io/LogSpan/operations/render";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/ImmutableMap/size";
/**
 * @tsplus static ets/Logger/Ops default
 */

export 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;
  }
};

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