import pino, { type Logger } from "pino";

export const logLevel = process.env.LOG_LEVEL || "info";

const transport = pino.transport({
	targets: [
		{
			target: "pino-pretty",
			options: {
				colorize: true,
				singleLine: true,
				// customPrettifiers: {
				//     time: (time) => `🕰 ${time}`,
				// },
				destination: process.stdout.fd,
			},
		},
		{
			target: "./dbTransport.js",
		},
		{
			target: "./notification.js",
		},
		// Only log to Go if LST_USE_GO=true
		...(process.env.LST_USE_GO === "true"
			? [
					{
						target: "./goTransport.js", // New transport for Go
					},
				]
			: []),
	],
});

export const rootLogger: Logger = pino(
	{
		level: logLevel,
		redact: { paths: ["email", "password"], remove: true },
	},
	transport,
);

/**
 * factory to create child to log things for us
 */
export function createLogger(bindings: Record<string, unknown>): Logger {
	return rootLogger.child(bindings);
}
