// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { Logger } from "./logger.ts";
import { state } from "./_state.ts";

/** Get a logger instance. If not specified `name`, get the default logger. */
export function getLogger(name?: string): Logger {
  if (!name) {
    const d = state.loggers.get("default");
    if (d === undefined) {
      throw new Error(
        `"default" logger must be set for getting logger without name`,
      );
    }
    return d;
  }
  const result = state.loggers.get(name);
  if (!result) {
    const logger = new Logger(name, "NOTSET", { handlers: [] });
    state.loggers.set(name, logger);
    return logger;
  }
  return result;
}

// denoCacheMetadata={"headers":{"access-control-expose-headers":"*","server":"cloudflare","date":"Tue, 28 Jul 2026 12:31:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=QCWCZMAEtmuiYHnsB76bbaIFp2Y49eRqEtRu62C9PQ%2BSIcafRh4bBKshAOq8ubErx1bTm7iBJpB%2BvbDXArommtFC6kOMXbYZtn68AwTKscJ6fM5CcYZmw%2FE%3D\"}]}","x-content-type-options":"nosniff","x-jsr-backend":"modules","access-control-allow-origin":"*","content-length":"737","etag":"\"62cd32c10d557f5d3503b32de744b663\"","set-cookie":"__cf_bm=3p5mOy45ljvSRM_b18SPjh3mWVrqsTeClW.6K0UD3g8-1785241875.1255941-1.0.1.1-bGrdTI_kimR9y9nrvPq_EbWf2fWikiHuPWvv6OAE.dTh7wspvYyJ6kGpdDF5gwxuqCA3MJnPR2Hb0lBVjGXMhNltYRQndijhDRagVS1nSpLQISDH3m50Wiz6_lub6.AJ; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","alt-svc":"h3=\":443\"; ma=86400","vary":"Origin","cross-origin-resource-policy":"cross-origin","content-type":"text/typescript","x-robots-tag":"noindex","cache-control":"public, max-age=31536000, immutable","cf-ray":"a223e65789cd7db6-LAX"},"url":"https://jsr.io/@std/log/0.224.7/get_logger.ts","time":1785241875}