// src/logger/ConsoleLogger.ts
class ConsoleLogger {
  name;
  level;
  colors;
  timestamps;
  static COLORS = {
    DEBUG: "\x1B[36m",
    INFO: "\x1B[32m",
    WARN: "\x1B[33m",
    ERROR: "\x1B[31m",
    RESET: "\x1B[0m"
  };
  constructor(name, options = {}) {
    this.name = name;
    this.level = options.level ?? "info";
    this.colors = options.colors ?? this.isNodeEnvironment();
    this.timestamps = options.timestamps ?? true;
  }
  debug(message, context) {
    if (this.isDebugEnabled()) {
      this.log("DEBUG", message, context);
    }
  }
  info(message, context) {
    if (this.isInfoEnabled()) {
      this.log("INFO", message, context);
    }
  }
  warn(message, context) {
    if (this.isWarnEnabled()) {
      this.log("WARN", message, context);
    }
  }
  error(message, context) {
    if (this.isErrorEnabled()) {
      if (message instanceof Error) {
        this.log("ERROR", message.message, { ...context, stack: message.stack });
      } else {
        this.log("ERROR", message, context);
      }
    }
  }
  isDebugEnabled() {
    return this.getLevelValue(this.level) <= this.getLevelValue("debug");
  }
  isInfoEnabled() {
    return this.getLevelValue(this.level) <= this.getLevelValue("info");
  }
  isWarnEnabled() {
    return this.getLevelValue(this.level) <= this.getLevelValue("warn");
  }
  isErrorEnabled() {
    return this.getLevelValue(this.level) <= this.getLevelValue("error");
  }
  getLevelValue(level) {
    const levels = {
      debug: 0,
      info: 1,
      warn: 2,
      error: 3,
      silent: 4
    };
    return levels[level];
  }
  log(level, message, context) {
    const parts = [];
    if (this.timestamps) {
      parts.push(new Date().toISOString());
    }
    if (this.colors) {
      const color = ConsoleLogger.COLORS[level];
      parts.push(`${color}${level.padEnd(5)}${ConsoleLogger.COLORS.RESET}`);
    } else {
      parts.push(level.padEnd(5));
    }
    parts.push(`[${this.name}]`);
    parts.push(message);
    const logLine = parts.join(" ");
    const consoleMethod = this.getConsoleMethod(level);
    if (context && Object.keys(context).length > 0) {
      consoleMethod(logLine, context);
    } else {
      consoleMethod(logLine);
    }
  }
  getConsoleMethod(level) {
    switch (level) {
      case "DEBUG":
        return console.debug.bind(console);
      case "INFO":
        return console.info.bind(console);
      case "WARN":
        return console.warn.bind(console);
      case "ERROR":
        return console.error.bind(console);
      default:
        return console.log.bind(console);
    }
  }
  isNodeEnvironment() {
    return typeof process !== "undefined" && process.versions?.node !== undefined;
  }
}
// src/logger/LoggerFactoryImpl.ts
var externalFactory = null;
var factoryVersion = 0;

class LoggerFactoryImpl {
  static loggers = new Map;
  static config = {
    defaultLevel: "info"
  };
  static getLogger(nameOrClass) {
    const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
    if (this.loggers.has(name)) {
      return this.loggers.get(name);
    }
    const lazyLogger = this.createLazyLogger(name);
    this.loggers.set(name, lazyLogger);
    return lazyLogger;
  }
  static configure(config) {
    this.config = { ...this.config, ...config };
  }
  static reset() {
    this.loggers.clear();
    this.config = { defaultLevel: "info" };
    externalFactory = null;
    factoryVersion++;
  }
  static createLazyLogger(name) {
    let realLogger = null;
    let loggerVersion = -1;
    const getRealLogger = () => {
      if (!realLogger || loggerVersion !== factoryVersion) {
        realLogger = this.createLogger(name);
        loggerVersion = factoryVersion;
      }
      return realLogger;
    };
    return {
      name,
      level: this.config.defaultLevel || "info",
      debug: (message, context) => getRealLogger().debug(message, context),
      info: (message, context) => getRealLogger().info(message, context),
      warn: (message, context) => getRealLogger().warn(message, context),
      error: (message, context) => getRealLogger().error(message, context),
      isDebugEnabled: () => getRealLogger().isDebugEnabled(),
      isInfoEnabled: () => getRealLogger().isInfoEnabled(),
      isWarnEnabled: () => getRealLogger().isWarnEnabled(),
      isErrorEnabled: () => getRealLogger().isErrorEnabled()
    };
  }
  static createLogger(name) {
    if (externalFactory) {
      return externalFactory.getLogger(name);
    }
    if (this.config.defaultImplementation) {
      return this.config.defaultImplementation(name);
    }
    return new ConsoleLogger(name, {
      level: this.config.defaultLevel,
      ...this.config.consoleOptions
    });
  }
}
function setLoggerFactory(factory) {
  externalFactory = factory;
  LoggerFactoryImpl.reset();
  externalFactory = factory;
}
function createLogger(name) {
  return LoggerFactoryImpl.getLogger(name);
}
export {
  setLoggerFactory,
  createLogger,
  LoggerFactoryImpl,
  ConsoleLogger
};

//# debugId=4E9DCBA7473CCEA164756E2164756E21
