const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
const require_forge$1 = require('./forge.cjs');
const require_util$1 = require('./util.cjs');

//#region ../../node_modules/node-forge/lib/log.js
var require_log = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/node-forge/lib/log.js": ((exports, module) => {
	/**
	* Cross-browser support for logging in a web application.
	*
	* @author David I. Lehn <dlehn@digitalbazaar.com>
	*
	* Copyright (c) 2008-2013 Digital Bazaar, Inc.
	*/
	var forge = require_forge$1.default;
	require_util$1.default;
	module.exports = forge.log = forge.log || {};
	/**
	* Application logging system.
	*
	* Each logger level available as it's own function of the form:
	*   forge.log.level(category, args...)
	* The category is an arbitrary string, and the args are the same as
	* Firebug's console.log API. By default the call will be output as:
	*   'LEVEL [category] <args[0]>, args[1], ...'
	* This enables proper % formatting via the first argument.
	* Each category is enabled by default but can be enabled or disabled with
	* the setCategoryEnabled() function.
	*/
	forge.log.levels = [
		"none",
		"error",
		"warning",
		"info",
		"debug",
		"verbose",
		"max"
	];
	var sLevelInfo = {};
	var sLoggers = [];
	/**
	* Standard console logger. If no console support is enabled this will
	* remain null. Check before using.
	*/
	var sConsoleLogger = null;
	/**
	* Lock the level at the current value. Used in cases where user config may
	* set the level such that only critical messages are seen but more verbose
	* messages are needed for debugging or other purposes.
	*/
	forge.log.LEVEL_LOCKED = 2;
	/**
	* Always call log function. By default, the logging system will check the
	* message level against logger.level before calling the log function. This
	* flag allows the function to do its own check.
	*/
	forge.log.NO_LEVEL_CHECK = 4;
	/**
	* Perform message interpolation with the passed arguments. "%" style
	* fields in log messages will be replaced by arguments as needed. Some
	* loggers, such as Firebug, may do this automatically. The original log
	* message will be available as 'message' and the interpolated version will
	* be available as 'fullMessage'.
	*/
	forge.log.INTERPOLATE = 8;
	for (var i = 0; i < forge.log.levels.length; ++i) {
		var level = forge.log.levels[i];
		sLevelInfo[level] = {
			index: i,
			name: level.toUpperCase()
		};
	}
	/**
	* Message logger. Will dispatch a message to registered loggers as needed.
	*
	* @param message message object
	*/
	forge.log.logMessage = function(message) {
		var messageLevelIndex = sLevelInfo[message.level].index;
		for (var i$1 = 0; i$1 < sLoggers.length; ++i$1) {
			var logger$1 = sLoggers[i$1];
			if (logger$1.flags & forge.log.NO_LEVEL_CHECK) logger$1.f(message);
			else if (messageLevelIndex <= sLevelInfo[logger$1.level].index) logger$1.f(logger$1, message);
		}
	};
	/**
	* Sets the 'standard' key on a message object to:
	* "LEVEL [category] " + message
	*
	* @param message a message log object
	*/
	forge.log.prepareStandard = function(message) {
		if (!("standard" in message)) message.standard = sLevelInfo[message.level].name + " [" + message.category + "] " + message.message;
	};
	/**
	* Sets the 'full' key on a message object to the original message
	* interpolated via % formatting with the message arguments.
	*
	* @param message a message log object.
	*/
	forge.log.prepareFull = function(message) {
		if (!("full" in message)) {
			var args = [message.message];
			args = args.concat([]);
			message.full = forge.util.format.apply(this, args);
		}
	};
	/**
	* Applies both preparseStandard() and prepareFull() to a message object and
	* store result in 'standardFull'.
	*
	* @param message a message log object.
	*/
	forge.log.prepareStandardFull = function(message) {
		if (!("standardFull" in message)) {
			forge.log.prepareStandard(message);
			message.standardFull = message.standard;
		}
	};
	var levels = [
		"error",
		"warning",
		"info",
		"debug",
		"verbose"
	];
	for (var i = 0; i < levels.length; ++i) (function(level$1) {
		forge.log[level$1] = function(category, message) {
			var args = Array.prototype.slice.call(arguments).slice(2);
			var msg = {
				timestamp: /* @__PURE__ */ new Date(),
				level: level$1,
				category,
				message,
				"arguments": args
			};
			forge.log.logMessage(msg);
		};
	})(levels[i]);
	/**
	* Creates a new logger with specified custom logging function.
	*
	* The logging function has a signature of:
	*   function(logger, message)
	* logger: current logger
	* message: object:
	*   level: level id
	*   category: category
	*   message: string message
	*   arguments: Array of extra arguments
	*   fullMessage: interpolated message and arguments if INTERPOLATE flag set
	*
	* @param logFunction a logging function which takes a log message object
	*          as a parameter.
	*
	* @return a logger object.
	*/
	forge.log.makeLogger = function(logFunction) {
		var logger$1 = {
			flags: 0,
			f: logFunction
		};
		forge.log.setLevel(logger$1, "none");
		return logger$1;
	};
	/**
	* Sets the current log level on a logger.
	*
	* @param logger the target logger.
	* @param level the new maximum log level as a string.
	*
	* @return true if set, false if not.
	*/
	forge.log.setLevel = function(logger$1, level$1) {
		var rval = false;
		if (logger$1 && !(logger$1.flags & forge.log.LEVEL_LOCKED)) {
			for (var i$1 = 0; i$1 < forge.log.levels.length; ++i$1) if (level$1 == forge.log.levels[i$1]) {
				logger$1.level = level$1;
				rval = true;
				break;
			}
		}
		return rval;
	};
	/**
	* Locks the log level at its current value.
	*
	* @param logger the target logger.
	* @param lock boolean lock value, default to true.
	*/
	forge.log.lock = function(logger$1, lock) {
		if (typeof lock === "undefined" || lock) logger$1.flags |= forge.log.LEVEL_LOCKED;
		else logger$1.flags &= ~forge.log.LEVEL_LOCKED;
	};
	/**
	* Adds a logger.
	*
	* @param logger the logger object.
	*/
	forge.log.addLogger = function(logger$1) {
		sLoggers.push(logger$1);
	};
	if (typeof console !== "undefined" && "log" in console) {
		var logger;
		if (console.error && console.warn && console.info && console.debug) {
			var levelHandlers = {
				error: console.error,
				warning: console.warn,
				info: console.info,
				debug: console.debug,
				verbose: console.debug
			};
			var f = function(logger$1, message) {
				forge.log.prepareStandard(message);
				var handler = levelHandlers[message.level];
				var args = [message.standard];
				args = args.concat(message["arguments"].slice());
				handler.apply(console, args);
			};
			logger = forge.log.makeLogger(f);
		} else {
			var f = function(logger$1, message) {
				forge.log.prepareStandardFull(message);
				console.log(message.standardFull);
			};
			logger = forge.log.makeLogger(f);
		}
		forge.log.setLevel(logger, "debug");
		forge.log.addLogger(logger);
		sConsoleLogger = logger;
	} else console = { log: function() {} };
	if (sConsoleLogger !== null && typeof window !== "undefined" && window.location) {
		var query = new URL(window.location.href).searchParams;
		if (query.has("console.level")) forge.log.setLevel(sConsoleLogger, query.get("console.level").slice(-1)[0]);
		if (query.has("console.lock")) {
			if (query.get("console.lock").slice(-1)[0] == "true") forge.log.lock(sConsoleLogger);
		}
	}
	forge.log.consoleLogger = sConsoleLogger;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_log();
  }
});
//# sourceMappingURL=log.cjs.map