import { n as toJsonValue, t as toJsonObject } from "./json-safe-BegdiS6Z.js";
//#region src/logger.ts
const LEVEL_ORDER = {
	debug: 10,
	info: 20,
	warn: 30,
	error: 40
};
function defaultWrite(record) {
	const line = JSON.stringify(record);
	switch (record.level) {
		case "debug":
			console.debug(line);
			break;
		case "info":
			console.info(line);
			break;
		case "warn":
			console.warn(line);
			break;
		case "error": console.error(line);
	}
}
function createLogger(options = {}) {
	const threshold = LEVEL_ORDER[options.level ?? "info"];
	const write = options.write ?? defaultWrite;
	const now = options.now ?? (() => /* @__PURE__ */ new Date());
	const baseContext = toJsonObject(options.context);
	const emit = (level, message, context, error) => {
		if (LEVEL_ORDER[level] < threshold) return;
		const record = {
			...baseContext,
			...toJsonObject(context),
			...error === void 0 ? {} : { error: toJsonValue(error) },
			timestamp: now().toISOString(),
			level,
			message
		};
		write(record);
	};
	return {
		debug: (message, context) => emit("debug", message, context),
		info: (message, context) => emit("info", message, context),
		warn: (message, context) => emit("warn", message, context),
		error: (message, error, context) => emit("error", message, context, error),
		child(context) {
			return createLogger({
				level: options.level,
				context: {
					...baseContext,
					...toJsonObject(context)
				},
				write,
				now
			});
		}
	};
}
//#endregion
export { createLogger };
