A transport for Victoria Metrics' VictoriaLogs for the LogLayer logging library.
This transport is a wrapper around the HTTP transport using the VictoriaLogs JSON stream API.
npm install loglayer @loglayer/transport-victoria-logs serialize-error
import { LogLayer } from 'loglayer'
import { VictoriaLogsTransport } from "@loglayer/transport-victoria-logs"
import { serializeError } from "serialize-error";
const log = new LogLayer({
errorSerializer: serializeError,
transport: new VictoriaLogsTransport({
url: "http://localhost:9428", // optional, defaults to http://localhost:9428
// Configure stream-level fields for better performance
streamFields: () => ({
service: "my-app",
environment: process.env.NODE_ENV || "development",
instance: process.env.HOSTNAME || "unknown",
}),
// Custom timestamp function (optional)
timestamp: () => new Date().toISOString(),
// Custom HTTP parameters for VictoriaLogs ingestion
httpParameters: {
_time_field: "_time",
_msg_field: "_msg",
},
// All other HttpTransport options are available and optional
compression: false, // optional, defaults to false
maxRetries: 3, // optional, defaults to 3
retryDelay: 1000, // optional, defaults to 1000
respectRateLimit: true, // optional, defaults to true
enableBatchSend: true, // optional, defaults to true
batchSize: 100, // optional, defaults to 100
batchSendTimeout: 5000, // optional, defaults to 5000ms
onError: (err) => {
console.error('Failed to send logs to VictoriaLogs:', err);
},
onDebug: (entry) => {
console.log('Log entry being sent to VictoriaLogs:', entry);
},
})
})
// Use the logger
log.info("This is a test message");
log.withMetadata({ userId: "123" }).error("User not found");
99% of this code was vibe-coded using Cursor and in the agent auto
mode with some supervision.
See the Prompts file for the prompts used.
For more details, visit https://loglayer.dev/transports/victoria-logs
- LogLayer Documentation - Main LogLayer documentation
- HTTP Transport - The underlying HTTP transport
- VictoriaLogs Documentation - Official VictoriaLogs documentation
- VictoriaLogs JSON Stream API - API documentation for the JSON stream endpoint
- VictoriaLogs HTTP Parameters - HTTP query parameters documentation
- VictoriaLogs Stream Fields - Stream fields documentation