UNPKG

@loglayer/transport-victoria-logs

Version:

VictoriaLogs transport for the LogLayer logging library.

109 lines (107 loc) 3.51 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { VictoriaLogsTransport: () => VictoriaLogsTransport }); module.exports = __toCommonJS(index_exports); // src/VictoriaLogsTransport.ts var import_transport_http = require("@loglayer/transport-http"); var VictoriaLogsTransport = class extends import_transport_http.HttpTransport { constructor(config = {}) { const { url = "http://localhost:9428", method = "POST", headers = { "Content-Type": "application/stream+json" }, contentType = "application/stream+json", batchContentType = "application/stream+json", streamFields = () => ({}), timestamp = () => (/* @__PURE__ */ new Date()).toISOString(), httpParameters = {}, payloadTemplate = ({ logLevel, message, data }) => { const streamFieldsData2 = streamFields(); const timeValue = timestamp(); const msgField = httpParameters._msg_field || "_msg"; const timeField = httpParameters._time_field || "_time"; return JSON.stringify({ [msgField]: message || "(no message)", [timeField]: timeValue, level: logLevel, ...streamFieldsData2, ...data }); }, compression = false, maxRetries = 3, retryDelay = 1e3, respectRateLimit = true, enableBatchSend = true, batchSize = 100, batchSendTimeout = 5e3, batchSendDelimiter = "\n", maxLogSize = 1048576, // 1MB maxPayloadSize = 5242880, // 5MB enableNextJsEdgeCompat = false, onError, onDebug, ...restConfig } = config; const streamFieldsData = streamFields(); const streamFieldsKeys = Object.keys(streamFieldsData); const finalHttpParameters = { ...httpParameters, ...streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(",") } }; const baseUrl = `${url.replace(/\/$/, "")}/insert/jsonline`; const queryParams = new URLSearchParams(finalHttpParameters); const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl; super({ url: fullUrl, method, headers, contentType, batchContentType, payloadTemplate, compression, maxRetries, retryDelay, respectRateLimit, enableBatchSend, batchSize, batchSendTimeout, batchSendDelimiter, maxLogSize, maxPayloadSize, enableNextJsEdgeCompat, onError, onDebug, ...restConfig }); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { VictoriaLogsTransport }); //# sourceMappingURL=index.cjs.map