@loglayer/transport-victoria-logs
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

VictoriaLogs Transport for LogLayer

NPM Version NPM Downloads TypeScript

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.

Installation

npm install loglayer @loglayer/transport-victoria-logs serialize-error

Usage

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");

Vibe code notice

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.

Documentation

For more details, visit https://loglayer.dev/transports/victoria-logs

Related

Package Sidebar

Install

npm i @loglayer/transport-victoria-logs

Weekly Downloads

19

Version

1.0.3

License

MIT

Unpacked Size

28.1 kB

Total Files

9

Last publish

Collaborators

  • theo.gravity