"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "createLokiLoggingTransport", {
    enumerable: true,
    get: function() {
        return createLokiLoggingTransport;
    }
});
const _winstonloki = /*#__PURE__*/ _interop_require_default(require("winston-loki"));
const _winston = /*#__PURE__*/ _interop_require_default(require("winston"));
const _nodeprocess = /*#__PURE__*/ _interop_require_default(require("node:process"));
const _serverconstants = require("../../server.constants");
const _zod = require("zod");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const lokiValidationSchema = _zod.z.object({
    lokiEnabled: _zod.z.boolean(),
    lokiAddress: _zod.z.string().url(),
    lokiTimeoutSeconds: _zod.z.coerce.number().positive().default(30),
    lokiInterval: _zod.z.coerce.number().positive().default(15)
});
function createLokiLoggingTransport(options) {
    const lokiConfigValidationResult = lokiValidationSchema.safeParse({
        lokiEnabled: _nodeprocess.default.env[_serverconstants.AppConstants.ENABLE_LOKI_LOGGING] === "true",
        lokiTimeoutSeconds: _nodeprocess.default.env[_serverconstants.AppConstants.LOKI_TIMEOUT_SECONDS],
        lokiAddress: _nodeprocess.default.env[_serverconstants.AppConstants.LOKI_ADDRESS],
        lokiInterval: _nodeprocess.default.env[_serverconstants.AppConstants.LOKI_INTERVAL]
    });
    if (!lokiConfigValidationResult.success || !lokiConfigValidationResult.data.lokiEnabled) {
        return;
    }
    return new _winstonloki.default({
        level: options.logLevel ?? "info",
        host: lokiConfigValidationResult.data.lokiAddress,
        interval: lokiConfigValidationResult.data.lokiInterval,
        timeout: lokiConfigValidationResult.data.lokiTimeoutSeconds,
        handleExceptions: true,
        onConnectionError (error) {
            console.debug(`Loki logger enabled, but connection failed. ${error}`);
        },
        labels: {
            app: "fdm-monster-server"
        },
        json: false,
        useWinstonMetaAsLabels: false,
        format: _winston.default.format.json()
    });
}

//# sourceMappingURL=loki-logging.transport.js.map