import { __esmMin } from "../../../_virtual/_rolldown/runtime.js";
import { PACKAGE_VERSION, init_package_version } from "../../package-version.js";
import { config, getLogDir, getLoggerConfig, init_config } from "./config.js";
import { init_streams, initializeStreams } from "./streams.js";
import { getLogStats, incrementStats, init_stats } from "./stats.js";
import { flushAndClose, init_shutdown, isLoggerShuttingDown, setShuttingDown } from "./shutdown.js";
import { cleanOldLogs, init_rotation, rotateLogs } from "./rotation.js";
import { clearRequestContext, getAsyncLogContext, getAsyncLogCorrelationKeys, inboundCorrelationMetadataFromAsyncLogContext, init_context, mergeContext, runWithLogContext, setRequestContext, updateAsyncLogContext } from "./context.js";
import { init_redact, isLogRedactionEnabled, redactLogRecord, redactObject, redactPemBlock, redactSecret, redactSensitiveInfo } from "./redact.js";
import { exportLog, flushExporters, getExporters, init_exporters, initializeExporters } from "./exporters.js";
import { configureAuditLog, getAuditConfig, init_audit, logAuditEvent, logAuthEvent, logConfigChange, logDataAccess, logPermissionChange } from "./audit.js";
import pino from "pino";
//#region src/utils/logger/index.ts
/**
* Modular Logger System
* 
* Production-grade logging with:
* - Modular architecture
* - Context tracking
* - Statistics
* - Graceful shutdown
*/
function wrapLogMethod(method, defaultContext, level) {
	return function(data, msg) {
		if (isLoggerShuttingDown()) {
			if (level !== "error" && level !== "fatal") return;
		}
		incrementStats(level, defaultContext.module || defaultContext.prefix);
		return msg !== void 0 ? method.call(this, data, msg) : method.call(this, data);
	};
}
function createProxyLogger(logger, defaultContext = {}) {
	return new Proxy(logger, { get(target, prop) {
		const propKey = prop;
		if (prop === "withContext") return (context) => {
			return createProxyLogger(target.child({ ...context }), mergeContext(defaultContext, context));
		};
		if (prop === "childContext") return (context) => {
			return createProxyLogger(target.child({ ...context }), mergeContext(defaultContext, context));
		};
		const value = target[propKey];
		if (typeof value === "function") {
			if ([
				"trace",
				"debug",
				"info",
				"warn",
				"error",
				"fatal"
			].includes(propKey)) return wrapLogMethod(value, defaultContext, propKey);
		}
		return value;
	} });
}
function createLogger(prefix, context) {
	return createProxyLogger(baseLogger.child({ prefix }), {
		module: prefix,
		...context
	});
}
function createModuleLogger(moduleName, _modulePath) {
	return createProxyLogger(baseLogger.child({ module: moduleName }), { module: moduleName });
}
function createExtensionLogger(extensionName) {
	return createProxyLogger(baseLogger.child({ extension: extensionName }), { extension: extensionName });
}
function createServiceLogger(serviceId) {
	return createProxyLogger(baseLogger.child({
		service: "cron",
		scope: serviceId
	}), {
		service: "cron",
		scope: serviceId
	});
}
function createRequestLogger(requestId, initialContext) {
	const context = {
		requestId,
		...initialContext
	};
	return createProxyLogger(baseLogger.child({ requestId }), context);
}
function setLogLevel(level) {
	baseLogger.level = level;
}
function getLogLevel() {
	return baseLogger.level;
}
function withLogLevel(level, fn) {
	const previous = baseLogger.level;
	baseLogger.level = level;
	try {
		return fn();
	} finally {
		baseLogger.level = previous;
	}
}
function isLevelEnabled(level) {
	const levelValues = {
		trace: 10,
		debug: 20,
		info: 30,
		warn: 40,
		error: 50,
		fatal: 60,
		silent: Number.MAX_VALUE
	};
	const currentLevelValues = {
		trace: 10,
		debug: 20,
		info: 30,
		warn: 40,
		error: 50,
		fatal: 60,
		silent: Number.MAX_VALUE
	};
	return levelValues[level] >= currentLevelValues[getLogLevel()];
}
function registerShutdownHandler() {}
var pinoOptions, streams, baseLogger, logger;
var init_logger = __esmMin((() => {
	init_config();
	init_streams();
	init_stats();
	init_shutdown();
	init_rotation();
	init_context();
	init_redact();
	init_package_version();
	init_exporters();
	init_audit();
	pinoOptions = {
		level: config.level,
		base: {
			service: "xopc",
			version: process.env.npm_package_version || PACKAGE_VERSION
		},
		timestamp: pino.stdTimeFunctions.isoTime,
		mixin(mergeObject, _level, logger) {
			const ctx = getAsyncLogContext();
			if (!ctx) return {};
			const bindings = logger && typeof logger.bindings === "function" ? logger.bindings() : {};
			const mo = mergeObject;
			const out = {};
			for (const key of getAsyncLogCorrelationKeys()) {
				const v = ctx[key];
				if (v === void 0 || v === "") continue;
				if (mo[key] !== void 0) continue;
				if (bindings[key] !== void 0) continue;
				out[key] = v;
			}
			return out;
		},
		formatters: {
			level: (label) => ({ level: label }),
			bindings: (bindings) => ({
				pid: bindings.pid,
				host: bindings.host
			}),
			log: (object) => {
				if (object.err && object.err instanceof Error) object.err = {
					name: object.err.name,
					message: object.err.message,
					stack: object.err.stack,
					cause: object.err.cause instanceof Error ? {
						name: object.err.cause.name,
						message: object.err.cause.message,
						stack: object.err.cause.stack
					} : object.err.cause
				};
				for (const key of Object.keys(object)) if (object[key] instanceof Error) object[key] = {
					name: object[key].name,
					message: object[key].message,
					stack: object[key].stack
				};
				return redactLogRecord(object);
			}
		},
		customLevels: {
			trace: 10,
			debug: 20,
			info: 30,
			warn: 40,
			error: 50,
			fatal: 60
		}
	};
	if (config.prettyPrint) pinoOptions.transport = {
		target: "pino-pretty",
		options: {
			colorize: true,
			translateTime: "SYS:standard",
			ignore: "pid,host"
		}
	};
	streams = initializeStreams();
	baseLogger = pino(pinoOptions, pino.multistream(streams));
	logger = createProxyLogger(baseLogger);
}));
//#endregion
init_logger();
export { pino as Pino, logger as baseLogger, logger as default, logger, cleanOldLogs, clearRequestContext as clearRequestLogger, configureAuditLog, createExtensionLogger, createLogger, createModuleLogger, createRequestLogger, createServiceLogger, exportLog, flushAndClose, flushExporters, getAsyncLogContext, getAuditConfig, getExporters, getLogDir, getLogLevel, getLogStats, getLoggerConfig, inboundCorrelationMetadataFromAsyncLogContext, init_logger, initializeExporters, isLevelEnabled, isLogRedactionEnabled, isLoggerShuttingDown, logAuditEvent, logAuthEvent, logConfigChange, logDataAccess, logPermissionChange, redactObject, redactPemBlock, redactSecret, redactSensitiveInfo, registerShutdownHandler, rotateLogs, runWithLogContext, setLogLevel, setRequestContext as setRequestLogger, setShuttingDown, updateAsyncLogContext, withLogLevel };

//# sourceMappingURL=index.js.map