Skip to main content
Home

Built and signed on GitHub Actions

File sink and rotating file sink for LogTape

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
4 days ago (1.0.4)
function getStreamFileSink
getStreamFileSink(
path: string,
): Sink & Disposable

Create a high-performance stream-based file sink that writes log records to a file.

This sink uses Node.js PassThrough streams piped to WriteStreams for optimal I/O performance. It leverages the Node.js stream infrastructure to provide automatic backpressure management, efficient buffering, and asynchronous writes without blocking the main thread.

Performance Characteristics

  • High Performance: Optimized for high-volume logging scenarios
  • Non-blocking: Uses asynchronous I/O that doesn't block the main thread
  • Memory Efficient: Automatic backpressure prevents memory buildup
  • Stream-based: Leverages Node.js native stream optimizations

When to Use

Use this sink when you need:

  • High-performance file logging for production applications
  • Non-blocking I/O behavior for real-time applications
  • Automatic backpressure handling for high-volume scenarios
  • Simple file output without complex buffering configuration

For more control over buffering behavior, consider using getFileSink instead, which provides options for buffer size, flush intervals, and non-blocking modes.

Example

import { configure } from "@logtape/logtape";
import { getStreamFileSink } from "@logtape/file";

await configure({
  sinks: {
    file: getStreamFileSink("app.log", {
      highWaterMark: 32768  // 32KB buffer for high-volume logging
    })
  },
  loggers: [
    { category: ["myapp"], sinks: ["file"] }
  ]
});

Parameters

path: string

The path to the file to write logs to. The file will be created if it doesn't exist, or appended to if it does exist.

optional
options: StreamFileSinkOptions

Configuration options for the stream-based sink.

Return Type

Sink & Disposable

A sink that writes formatted log records to the specified file. The returned sink implements Disposable for proper resource cleanup.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";
or

Import directly with a jsr specifier

import { getStreamFileSink } from "jsr:@logtape/file";

Add Package

pnpm i jsr:@logtape/file
or (using pnpm 10.8 or older)
pnpm dlx jsr add @logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";

Add Package

yarn add jsr:@logtape/file
or (using Yarn 4.8 or older)
yarn dlx jsr add @logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";

Add Package

vlt install jsr:@logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";

Add Package

npx jsr add @logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";

Add Package

bunx jsr add @logtape/file

Import symbol

import { getStreamFileSink } from "@logtape/file";