import chalk from "chalk";
class Logger {
  name;
  logLevel;
  constructor(name, logLevel = "info") {
    this.name = name;
    this.logLevel = process.env["LOG_LEVEL"] || logLevel;
  }
  shouldLog(level) {
    const levels = ["debug", "info", "warn", "error"];
    const currentIndex = levels.indexOf(this.logLevel);
    const targetIndex = levels.indexOf(level);
    return targetIndex >= currentIndex;
  }
  formatMessage(level, message, ...args) {
    const timestamp = (/* @__PURE__ */ new Date()).toISOString();
    const prefix = `[${timestamp}] [${this.name}] [${level.toUpperCase()}]`;
    const formattedArgs = args.length > 0 ? " " + args.map(
      (arg) => typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg
    ).join(" ") : "";
    return `${prefix} ${message}${formattedArgs}`;
  }
  debug(message, ...args) {
    if (this.shouldLog("debug")) {
      console.log(chalk.gray(this.formatMessage("debug", message, ...args)));
    }
  }
  info(message, ...args) {
    if (this.shouldLog("info")) {
      console.log(chalk.blue(this.formatMessage("info", message, ...args)));
    }
  }
  warn(message, ...args) {
    if (this.shouldLog("warn")) {
      console.warn(chalk.yellow(this.formatMessage("warn", message, ...args)));
    }
  }
  error(message, error) {
    if (this.shouldLog("error")) {
      const errorDetails = error ? error instanceof Error ? `
${error.stack || error.message}` : `
${JSON.stringify(error, null, 2)}` : "";
      console.error(
        chalk.red(this.formatMessage("error", message) + errorDetails)
      );
    }
  }
}
export {
  Logger
};
//# sourceMappingURL=logger.js.map
