UNPKG

@loglayer/transport-victoria-logs

Version:

VictoriaLogs transport for the LogLayer logging library.

65 lines (63 loc) 2.57 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); let _loglayer_transport_http = require("@loglayer/transport-http"); //#region src/VictoriaLogsTransport.ts /** * VictoriaLogs transport for LogLayer. * * This transport is a thin wrapper around the HttpTransport that provides * VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs * JSON stream API to send logs. * * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api */ var VictoriaLogsTransport = class extends _loglayer_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 streamFieldsData = 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, ...streamFieldsData, ...data }); }, compression = false, maxRetries = 3, retryDelay = 1e3, respectRateLimit = true, enableBatchSend = true, batchSize = 100, batchSendTimeout = 5e3, batchSendDelimiter = "\n", maxLogSize = 1048576, maxPayloadSize = 5242880, 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 }); } }; //#endregion exports.VictoriaLogsTransport = VictoriaLogsTransport; //# sourceMappingURL=index.cjs.map