UNPKG

@loglayer/transport-victoria-logs

Version:

VictoriaLogs transport for the LogLayer logging library.

82 lines 2.44 kB
// src/VictoriaLogsTransport.ts import { HttpTransport } from "@loglayer/transport-http"; var VictoriaLogsTransport = class extends 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 }); } }; export { VictoriaLogsTransport }; //# sourceMappingURL=index.js.map