import debugPackage from "debug";
import { Writable } from "node:stream";
import { getEventPrefix, levels } from "./core.js";
const nodeLogDestination = {
  write(event) {
    let dest = process.stderr;
    if (levels[event.level] < levels["error"]) {
      dest = process.stdout;
    }
    if (event.label === "SKIP_FORMAT") {
      dest.write(event.message + "\n");
    } else {
      dest.write(getEventPrefix(event) + " " + event.message + "\n");
    }
    return true;
  }
};
const debuggers = {};
function debug(type, ...messages) {
  const namespace = `astro:${type}`;
  debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
  return debuggers[namespace](...messages);
}
globalThis._astroGlobalDebug = debug;
function enableVerboseLogging() {
  debugPackage.enable("*,-babel");
  debug("cli", '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
  debug(
    "cli",
    'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".'
  );
}
export {
  enableVerboseLogging,
  nodeLogDestination
};
