import pino from "pino";
import pinoPretty from "pino-pretty";

//#region src/utils/logger.ts
/**
* Pino logger implementation with transport customization support
*/
var PinoLogger = class {
	transportConfigs = [];
	pinoInstance;
	options;
	constructor(name, config = {}) {
		this.name = name;
		this.options = {
			name: this.name,
			level: process.env.LOG_LEVEL || (process.env.ENVIRONMENT === "test" ? "silent" : "info"),
			serializers: { obj: (value) => ({ ...value }) },
			redact: ["req.headers.authorization", "req.headers[\"x-inkeep-admin-authentication\"]"],
			...config.options
		};
		if (config.transportConfigs) this.transportConfigs = config.transportConfigs;
		if (this.transportConfigs.length > 0) this.pinoInstance = pino(this.options, pino.transport({ targets: this.transportConfigs }));
		else try {
			const prettyStream = pinoPretty({
				colorize: true,
				translateTime: "HH:MM:ss",
				ignore: "pid,hostname"
			});
			this.pinoInstance = pino(this.options, prettyStream);
		} catch (error) {
			console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
			this.pinoInstance = pino(this.options);
		}
	}
	/**
	* Recreate the pino instance with current transports
	*/
	recreateInstance() {
		if (this.pinoInstance && typeof this.pinoInstance.flush === "function") this.pinoInstance.flush();
		if (this.transportConfigs.length === 0) try {
			const prettyStream = pinoPretty({
				colorize: true,
				translateTime: "HH:MM:ss",
				ignore: "pid,hostname"
			});
			this.pinoInstance = pino(this.options, prettyStream);
		} catch (error) {
			console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
			this.pinoInstance = pino(this.options);
		}
		else {
			const multiTransport = { targets: this.transportConfigs };
			const pinoTransport = pino.transport(multiTransport);
			this.pinoInstance = pino(this.options, pinoTransport);
		}
	}
	/**
	* Add a new transport to the logger
	*/
	addTransport(transportConfig) {
		this.transportConfigs.push(transportConfig);
		this.recreateInstance();
	}
	/**
	* Remove a transport by index
	*/
	removeTransport(index) {
		if (index >= 0 && index < this.transportConfigs.length) {
			this.transportConfigs.splice(index, 1);
			this.recreateInstance();
		}
	}
	/**
	* Get current transports
	*/
	getTransports() {
		return [...this.transportConfigs];
	}
	/**
	* Update logger options
	*/
	updateOptions(options) {
		this.options = {
			...this.options,
			...options
		};
		this.recreateInstance();
	}
	/**
	* Get the underlying pino instance for advanced usage
	*/
	getPinoInstance() {
		return this.pinoInstance;
	}
	error(data, message) {
		this.pinoInstance.error(data, message);
	}
	warn(data, message) {
		this.pinoInstance.warn(data, message);
	}
	info(data, message) {
		this.pinoInstance.info(data, message);
	}
	debug(data, message) {
		this.pinoInstance.debug(data, message);
	}
};
/**
* Global logger factory singleton
*/
var LoggerFactory = class {
	config = {};
	loggers = /* @__PURE__ */ new Map();
	/**
	* Configure the logger factory
	*/
	configure(config) {
		this.config = config;
		this.loggers.clear();
	}
	/**
	* Get or create a logger instance
	*/
	getLogger(name) {
		if (this.loggers.has(name)) {
			const logger$1 = this.loggers.get(name);
			if (!logger$1) throw new Error(`Logger '${name}' not found in cache`);
			return logger$1;
		}
		let logger;
		if (this.config.loggerFactory) logger = this.config.loggerFactory(name);
		else if (this.config.defaultLogger) logger = this.config.defaultLogger;
		else logger = new PinoLogger(name, this.config.pinoConfig);
		this.loggers.set(name, logger);
		return logger;
	}
	/**
	* Reset factory to default state
	*/
	reset() {
		this.config = {};
		this.loggers.clear();
	}
};
const loggerFactory = new LoggerFactory();
/**
* Convenience function to get a logger
*/
function getLogger(name) {
	return loggerFactory.getLogger(name);
}

//#endregion
export { getLogger as n, loggerFactory as r, PinoLogger as t };
//# sourceMappingURL=logger.js.map