UNPKG

@roochnetwork/rooch-sdk

Version:
70 lines (69 loc) 1.88 kB
import debug from "debug"; const BASE_NAMESPACE = "rooch-sdk"; var LogLevel = /* @__PURE__ */ ((LogLevel2) => { LogLevel2["INFO"] = "info"; LogLevel2["WARN"] = "warn"; LogLevel2["ERROR"] = "error"; LogLevel2["DEBUG"] = "debug"; return LogLevel2; })(LogLevel || {}); function formatError(error) { if (error instanceof Error) { return `${error.name}: ${error.message}${error.stack ? ` ${error.stack}` : ""}`; } return String(error); } class RoochLogger { /** * Create a new logger instance for a specific module * * @param moduleName Name of the module (e.g., 'transport', 'client') * @param subModule Optional sub-module name (e.g., 'ws', 'http') */ constructor(moduleName, subModule) { const baseNamespace = subModule ? `${BASE_NAMESPACE}:${moduleName}:${subModule}` : `${BASE_NAMESPACE}:${moduleName}`; this.infoLogger = debug(`${baseNamespace}:info`); this.warnLogger = debug(`${baseNamespace}:warn`); this.errorLogger = debug(`${baseNamespace}:error`); this.debugLogger = debug(`${baseNamespace}:debug`); this.infoLogger.color = "36"; this.warnLogger.color = "33"; this.errorLogger.color = "31"; this.debugLogger.color = "90"; } /** * Log an informational message */ info(message, ...args) { this.infoLogger(message, ...args); } /** * Log a warning message */ warn(message, ...args) { this.warnLogger(message, ...args); } /** * Log an error message */ error(message, ...args) { this.errorLogger(message, ...args); } /** * Log a debug message (more verbose than info) */ debug(message, ...args) { this.debugLogger(message, ...args); } } function createLogger(moduleName, subModule) { return new RoochLogger(moduleName, subModule); } export { LogLevel, RoochLogger, createLogger, formatError }; //# sourceMappingURL=logger.js.map