@logtape/file 1.0.0-dev.237 → 1.0.0-dev.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/filesink.base.cjs +239 -22
- package/dist/filesink.base.d.cts +14 -0
- package/dist/filesink.base.d.cts.map +1 -1
- package/dist/filesink.base.d.ts +14 -0
- package/dist/filesink.base.d.ts.map +1 -1
- package/dist/filesink.base.js +239 -22
- package/dist/filesink.base.js.map +1 -1
- package/dist/filesink.deno.cjs +6 -0
- package/dist/filesink.deno.d.cts.map +1 -1
- package/dist/filesink.deno.d.ts.map +1 -1
- package/dist/filesink.deno.js +6 -0
- package/dist/filesink.deno.js.map +1 -1
- package/dist/filesink.node.cjs +16 -0
- package/dist/filesink.node.d.cts.map +1 -1
- package/dist/filesink.node.d.ts.map +1 -1
- package/dist/filesink.node.js +16 -0
- package/dist/filesink.node.js.map +1 -1
- package/dist/mod.cjs +3 -1
- package/dist/mod.d.cts +2 -1
- package/dist/mod.d.ts +2 -1
- package/dist/mod.js +2 -1
- package/dist/streamfilesink.cjs +84 -0
- package/dist/streamfilesink.d.cts +95 -0
- package/dist/streamfilesink.d.cts.map +1 -0
- package/dist/streamfilesink.d.ts +95 -0
- package/dist/streamfilesink.d.ts.map +1 -0
- package/dist/streamfilesink.js +84 -0
- package/dist/streamfilesink.js.map +1 -0
- package/filesink.base.ts +386 -25
- package/filesink.deno.ts +14 -0
- package/filesink.node.ts +18 -0
- package/mod.ts +2 -0
- package/package.json +2 -2
- package/streamfilesink.test.ts +336 -0
- package/streamfilesink.ts +136 -0
- package/tsdown.config.ts +2 -2
package/dist/mod.js
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
3
|
+
const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
|
|
4
|
+
const node_stream = require_rolldown_runtime.__toESM(require("node:stream"));
|
|
5
|
+
|
|
6
|
+
//#region streamfilesink.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a high-performance stream-based file sink that writes log records to a file.
|
|
9
|
+
*
|
|
10
|
+
* This sink uses Node.js PassThrough streams piped to WriteStreams for optimal
|
|
11
|
+
* I/O performance. It leverages the Node.js stream infrastructure to provide
|
|
12
|
+
* automatic backpressure management, efficient buffering, and asynchronous writes
|
|
13
|
+
* without blocking the main thread.
|
|
14
|
+
*
|
|
15
|
+
* ## Performance Characteristics
|
|
16
|
+
*
|
|
17
|
+
* - **High Performance**: Optimized for high-volume logging scenarios
|
|
18
|
+
* - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread
|
|
19
|
+
* - **Memory Efficient**: Automatic backpressure prevents memory buildup
|
|
20
|
+
* - **Stream-based**: Leverages Node.js native stream optimizations
|
|
21
|
+
*
|
|
22
|
+
* ## When to Use
|
|
23
|
+
*
|
|
24
|
+
* Use this sink when you need:
|
|
25
|
+
* - High-performance file logging for production applications
|
|
26
|
+
* - Non-blocking I/O behavior for real-time applications
|
|
27
|
+
* - Automatic backpressure handling for high-volume scenarios
|
|
28
|
+
* - Simple file output without complex buffering configuration
|
|
29
|
+
*
|
|
30
|
+
* For more control over buffering behavior, consider using {@link getFileSink}
|
|
31
|
+
* instead, which provides options for buffer size, flush intervals, and
|
|
32
|
+
* non-blocking modes.
|
|
33
|
+
*
|
|
34
|
+
* ## Example
|
|
35
|
+
*
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { configure } from "@logtape/logtape";
|
|
38
|
+
* import { getStreamFileSink } from "@logtape/file";
|
|
39
|
+
*
|
|
40
|
+
* await configure({
|
|
41
|
+
* sinks: {
|
|
42
|
+
* file: getStreamFileSink("app.log", {
|
|
43
|
+
* highWaterMark: 32768 // 32KB buffer for high-volume logging
|
|
44
|
+
* })
|
|
45
|
+
* },
|
|
46
|
+
* loggers: [
|
|
47
|
+
* { category: ["myapp"], sinks: ["file"] }
|
|
48
|
+
* ]
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param path The path to the file to write logs to. The file will be created
|
|
53
|
+
* if it doesn't exist, or appended to if it does exist.
|
|
54
|
+
* @param options Configuration options for the stream-based sink.
|
|
55
|
+
* @returns A sink that writes formatted log records to the specified file.
|
|
56
|
+
* The returned sink implements `Disposable` for proper resource cleanup.
|
|
57
|
+
*
|
|
58
|
+
* @since 1.0.0
|
|
59
|
+
*/
|
|
60
|
+
function getStreamFileSink(path, options = {}) {
|
|
61
|
+
const highWaterMark = options.highWaterMark ?? 16384;
|
|
62
|
+
const formatter = options.formatter ?? __logtape_logtape.defaultTextFormatter;
|
|
63
|
+
const passThrough = new node_stream.PassThrough({
|
|
64
|
+
highWaterMark,
|
|
65
|
+
objectMode: false
|
|
66
|
+
});
|
|
67
|
+
const writeStream = (0, node_fs.createWriteStream)(path, { flags: "a" });
|
|
68
|
+
passThrough.pipe(writeStream);
|
|
69
|
+
let disposed = false;
|
|
70
|
+
const sink = (record) => {
|
|
71
|
+
if (disposed) return;
|
|
72
|
+
passThrough.write(formatter(record));
|
|
73
|
+
};
|
|
74
|
+
sink[Symbol.dispose] = () => {
|
|
75
|
+
if (disposed) return;
|
|
76
|
+
disposed = true;
|
|
77
|
+
passThrough.end();
|
|
78
|
+
writeStream.end();
|
|
79
|
+
};
|
|
80
|
+
return sink;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.getStreamFileSink = getStreamFileSink;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Sink, TextFormatter } from "@logtape/logtape";
|
|
2
|
+
|
|
3
|
+
//#region streamfilesink.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for the {@link getStreamFileSink} function.
|
|
7
|
+
*
|
|
8
|
+
* This interface configures the high-performance stream-based file sink that
|
|
9
|
+
* uses Node.js PassThrough streams for optimal I/O performance with automatic
|
|
10
|
+
* backpressure management.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
interface StreamFileSinkOptions {
|
|
15
|
+
/**
|
|
16
|
+
* High water mark for the PassThrough stream buffer in bytes.
|
|
17
|
+
*
|
|
18
|
+
* This controls the internal buffer size of the PassThrough stream.
|
|
19
|
+
* Higher values can improve performance for high-volume logging but use
|
|
20
|
+
* more memory. Lower values reduce memory usage but may impact performance.
|
|
21
|
+
*
|
|
22
|
+
* @default 16384
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
readonly highWaterMark?: number;
|
|
26
|
+
/**
|
|
27
|
+
* A custom formatter for log records.
|
|
28
|
+
*
|
|
29
|
+
* If not specified, the default text formatter will be used, which formats
|
|
30
|
+
* records in the standard LogTape format with timestamp, level, category,
|
|
31
|
+
* and message.
|
|
32
|
+
*
|
|
33
|
+
* @default defaultTextFormatter
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
readonly formatter?: TextFormatter;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a high-performance stream-based file sink that writes log records to a file.
|
|
40
|
+
*
|
|
41
|
+
* This sink uses Node.js PassThrough streams piped to WriteStreams for optimal
|
|
42
|
+
* I/O performance. It leverages the Node.js stream infrastructure to provide
|
|
43
|
+
* automatic backpressure management, efficient buffering, and asynchronous writes
|
|
44
|
+
* without blocking the main thread.
|
|
45
|
+
*
|
|
46
|
+
* ## Performance Characteristics
|
|
47
|
+
*
|
|
48
|
+
* - **High Performance**: Optimized for high-volume logging scenarios
|
|
49
|
+
* - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread
|
|
50
|
+
* - **Memory Efficient**: Automatic backpressure prevents memory buildup
|
|
51
|
+
* - **Stream-based**: Leverages Node.js native stream optimizations
|
|
52
|
+
*
|
|
53
|
+
* ## When to Use
|
|
54
|
+
*
|
|
55
|
+
* Use this sink when you need:
|
|
56
|
+
* - High-performance file logging for production applications
|
|
57
|
+
* - Non-blocking I/O behavior for real-time applications
|
|
58
|
+
* - Automatic backpressure handling for high-volume scenarios
|
|
59
|
+
* - Simple file output without complex buffering configuration
|
|
60
|
+
*
|
|
61
|
+
* For more control over buffering behavior, consider using {@link getFileSink}
|
|
62
|
+
* instead, which provides options for buffer size, flush intervals, and
|
|
63
|
+
* non-blocking modes.
|
|
64
|
+
*
|
|
65
|
+
* ## Example
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { configure } from "@logtape/logtape";
|
|
69
|
+
* import { getStreamFileSink } from "@logtape/file";
|
|
70
|
+
*
|
|
71
|
+
* await configure({
|
|
72
|
+
* sinks: {
|
|
73
|
+
* file: getStreamFileSink("app.log", {
|
|
74
|
+
* highWaterMark: 32768 // 32KB buffer for high-volume logging
|
|
75
|
+
* })
|
|
76
|
+
* },
|
|
77
|
+
* loggers: [
|
|
78
|
+
* { category: ["myapp"], sinks: ["file"] }
|
|
79
|
+
* ]
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param path The path to the file to write logs to. The file will be created
|
|
84
|
+
* if it doesn't exist, or appended to if it does exist.
|
|
85
|
+
* @param options Configuration options for the stream-based sink.
|
|
86
|
+
* @returns A sink that writes formatted log records to the specified file.
|
|
87
|
+
* The returned sink implements `Disposable` for proper resource cleanup.
|
|
88
|
+
*
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
*/
|
|
91
|
+
declare function getStreamFileSink(path: string, options?: StreamFileSinkOptions): Sink & Disposable;
|
|
92
|
+
//# sourceMappingURL=streamfilesink.d.ts.map
|
|
93
|
+
//#endregion
|
|
94
|
+
export { StreamFileSinkOptions, getStreamFileSink };
|
|
95
|
+
//# sourceMappingURL=streamfilesink.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamfilesink.d.cts","names":[],"sources":["../streamfilesink.ts"],"sourcesContent":[],"mappings":";;;;;;AAkBA;AA+EA;;;;;AAGoB;UAlFH,qBAAA;;;;;;;;;;;;;;;;;;;;;;uBAuBM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwDP,iBAAA,yBAEL,wBACR,OAAO"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Sink, TextFormatter } from "@logtape/logtape";
|
|
2
|
+
|
|
3
|
+
//#region streamfilesink.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for the {@link getStreamFileSink} function.
|
|
7
|
+
*
|
|
8
|
+
* This interface configures the high-performance stream-based file sink that
|
|
9
|
+
* uses Node.js PassThrough streams for optimal I/O performance with automatic
|
|
10
|
+
* backpressure management.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
interface StreamFileSinkOptions {
|
|
15
|
+
/**
|
|
16
|
+
* High water mark for the PassThrough stream buffer in bytes.
|
|
17
|
+
*
|
|
18
|
+
* This controls the internal buffer size of the PassThrough stream.
|
|
19
|
+
* Higher values can improve performance for high-volume logging but use
|
|
20
|
+
* more memory. Lower values reduce memory usage but may impact performance.
|
|
21
|
+
*
|
|
22
|
+
* @default 16384
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
readonly highWaterMark?: number;
|
|
26
|
+
/**
|
|
27
|
+
* A custom formatter for log records.
|
|
28
|
+
*
|
|
29
|
+
* If not specified, the default text formatter will be used, which formats
|
|
30
|
+
* records in the standard LogTape format with timestamp, level, category,
|
|
31
|
+
* and message.
|
|
32
|
+
*
|
|
33
|
+
* @default defaultTextFormatter
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
readonly formatter?: TextFormatter;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a high-performance stream-based file sink that writes log records to a file.
|
|
40
|
+
*
|
|
41
|
+
* This sink uses Node.js PassThrough streams piped to WriteStreams for optimal
|
|
42
|
+
* I/O performance. It leverages the Node.js stream infrastructure to provide
|
|
43
|
+
* automatic backpressure management, efficient buffering, and asynchronous writes
|
|
44
|
+
* without blocking the main thread.
|
|
45
|
+
*
|
|
46
|
+
* ## Performance Characteristics
|
|
47
|
+
*
|
|
48
|
+
* - **High Performance**: Optimized for high-volume logging scenarios
|
|
49
|
+
* - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread
|
|
50
|
+
* - **Memory Efficient**: Automatic backpressure prevents memory buildup
|
|
51
|
+
* - **Stream-based**: Leverages Node.js native stream optimizations
|
|
52
|
+
*
|
|
53
|
+
* ## When to Use
|
|
54
|
+
*
|
|
55
|
+
* Use this sink when you need:
|
|
56
|
+
* - High-performance file logging for production applications
|
|
57
|
+
* - Non-blocking I/O behavior for real-time applications
|
|
58
|
+
* - Automatic backpressure handling for high-volume scenarios
|
|
59
|
+
* - Simple file output without complex buffering configuration
|
|
60
|
+
*
|
|
61
|
+
* For more control over buffering behavior, consider using {@link getFileSink}
|
|
62
|
+
* instead, which provides options for buffer size, flush intervals, and
|
|
63
|
+
* non-blocking modes.
|
|
64
|
+
*
|
|
65
|
+
* ## Example
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { configure } from "@logtape/logtape";
|
|
69
|
+
* import { getStreamFileSink } from "@logtape/file";
|
|
70
|
+
*
|
|
71
|
+
* await configure({
|
|
72
|
+
* sinks: {
|
|
73
|
+
* file: getStreamFileSink("app.log", {
|
|
74
|
+
* highWaterMark: 32768 // 32KB buffer for high-volume logging
|
|
75
|
+
* })
|
|
76
|
+
* },
|
|
77
|
+
* loggers: [
|
|
78
|
+
* { category: ["myapp"], sinks: ["file"] }
|
|
79
|
+
* ]
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param path The path to the file to write logs to. The file will be created
|
|
84
|
+
* if it doesn't exist, or appended to if it does exist.
|
|
85
|
+
* @param options Configuration options for the stream-based sink.
|
|
86
|
+
* @returns A sink that writes formatted log records to the specified file.
|
|
87
|
+
* The returned sink implements `Disposable` for proper resource cleanup.
|
|
88
|
+
*
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
*/
|
|
91
|
+
declare function getStreamFileSink(path: string, options?: StreamFileSinkOptions): Sink & Disposable;
|
|
92
|
+
//# sourceMappingURL=streamfilesink.d.ts.map
|
|
93
|
+
//#endregion
|
|
94
|
+
export { StreamFileSinkOptions, getStreamFileSink };
|
|
95
|
+
//# sourceMappingURL=streamfilesink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamfilesink.d.ts","names":[],"sources":["../streamfilesink.ts"],"sourcesContent":[],"mappings":";;;;;;AAkBA;AA+EA;;;;;AAGoB;UAlFH,qBAAA;;;;;;;;;;;;;;;;;;;;;;uBAuBM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAwDP,iBAAA,yBAEL,wBACR,OAAO"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { defaultTextFormatter } from "@logtape/logtape";
|
|
2
|
+
import { createWriteStream } from "node:fs";
|
|
3
|
+
import { PassThrough } from "node:stream";
|
|
4
|
+
|
|
5
|
+
//#region streamfilesink.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create a high-performance stream-based file sink that writes log records to a file.
|
|
8
|
+
*
|
|
9
|
+
* This sink uses Node.js PassThrough streams piped to WriteStreams for optimal
|
|
10
|
+
* I/O performance. It leverages the Node.js stream infrastructure to provide
|
|
11
|
+
* automatic backpressure management, efficient buffering, and asynchronous writes
|
|
12
|
+
* without blocking the main thread.
|
|
13
|
+
*
|
|
14
|
+
* ## Performance Characteristics
|
|
15
|
+
*
|
|
16
|
+
* - **High Performance**: Optimized for high-volume logging scenarios
|
|
17
|
+
* - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread
|
|
18
|
+
* - **Memory Efficient**: Automatic backpressure prevents memory buildup
|
|
19
|
+
* - **Stream-based**: Leverages Node.js native stream optimizations
|
|
20
|
+
*
|
|
21
|
+
* ## When to Use
|
|
22
|
+
*
|
|
23
|
+
* Use this sink when you need:
|
|
24
|
+
* - High-performance file logging for production applications
|
|
25
|
+
* - Non-blocking I/O behavior for real-time applications
|
|
26
|
+
* - Automatic backpressure handling for high-volume scenarios
|
|
27
|
+
* - Simple file output without complex buffering configuration
|
|
28
|
+
*
|
|
29
|
+
* For more control over buffering behavior, consider using {@link getFileSink}
|
|
30
|
+
* instead, which provides options for buffer size, flush intervals, and
|
|
31
|
+
* non-blocking modes.
|
|
32
|
+
*
|
|
33
|
+
* ## Example
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { configure } from "@logtape/logtape";
|
|
37
|
+
* import { getStreamFileSink } from "@logtape/file";
|
|
38
|
+
*
|
|
39
|
+
* await configure({
|
|
40
|
+
* sinks: {
|
|
41
|
+
* file: getStreamFileSink("app.log", {
|
|
42
|
+
* highWaterMark: 32768 // 32KB buffer for high-volume logging
|
|
43
|
+
* })
|
|
44
|
+
* },
|
|
45
|
+
* loggers: [
|
|
46
|
+
* { category: ["myapp"], sinks: ["file"] }
|
|
47
|
+
* ]
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param path The path to the file to write logs to. The file will be created
|
|
52
|
+
* if it doesn't exist, or appended to if it does exist.
|
|
53
|
+
* @param options Configuration options for the stream-based sink.
|
|
54
|
+
* @returns A sink that writes formatted log records to the specified file.
|
|
55
|
+
* The returned sink implements `Disposable` for proper resource cleanup.
|
|
56
|
+
*
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
function getStreamFileSink(path, options = {}) {
|
|
60
|
+
const highWaterMark = options.highWaterMark ?? 16384;
|
|
61
|
+
const formatter = options.formatter ?? defaultTextFormatter;
|
|
62
|
+
const passThrough = new PassThrough({
|
|
63
|
+
highWaterMark,
|
|
64
|
+
objectMode: false
|
|
65
|
+
});
|
|
66
|
+
const writeStream = createWriteStream(path, { flags: "a" });
|
|
67
|
+
passThrough.pipe(writeStream);
|
|
68
|
+
let disposed = false;
|
|
69
|
+
const sink = (record) => {
|
|
70
|
+
if (disposed) return;
|
|
71
|
+
passThrough.write(formatter(record));
|
|
72
|
+
};
|
|
73
|
+
sink[Symbol.dispose] = () => {
|
|
74
|
+
if (disposed) return;
|
|
75
|
+
disposed = true;
|
|
76
|
+
passThrough.end();
|
|
77
|
+
writeStream.end();
|
|
78
|
+
};
|
|
79
|
+
return sink;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { getStreamFileSink };
|
|
84
|
+
//# sourceMappingURL=streamfilesink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamfilesink.js","names":["path: string","options: StreamFileSinkOptions","sink: Sink & Disposable","record: LogRecord"],"sources":["../streamfilesink.ts"],"sourcesContent":["import {\n defaultTextFormatter,\n type LogRecord,\n type Sink,\n type TextFormatter,\n} from \"@logtape/logtape\";\nimport { createWriteStream } from \"node:fs\";\nimport { PassThrough } from \"node:stream\";\n\n/**\n * Options for the {@link getStreamFileSink} function.\n *\n * This interface configures the high-performance stream-based file sink that\n * uses Node.js PassThrough streams for optimal I/O performance with automatic\n * backpressure management.\n *\n * @since 1.0.0\n */\nexport interface StreamFileSinkOptions {\n /**\n * High water mark for the PassThrough stream buffer in bytes.\n *\n * This controls the internal buffer size of the PassThrough stream.\n * Higher values can improve performance for high-volume logging but use\n * more memory. Lower values reduce memory usage but may impact performance.\n *\n * @default 16384\n * @since 1.0.0\n */\n readonly highWaterMark?: number;\n\n /**\n * A custom formatter for log records.\n *\n * If not specified, the default text formatter will be used, which formats\n * records in the standard LogTape format with timestamp, level, category,\n * and message.\n *\n * @default defaultTextFormatter\n * @since 1.0.0\n */\n readonly formatter?: TextFormatter;\n}\n\n/**\n * Create a high-performance stream-based file sink that writes log records to a file.\n *\n * This sink uses Node.js PassThrough streams piped to WriteStreams for optimal\n * I/O performance. It leverages the Node.js stream infrastructure to provide\n * automatic backpressure management, efficient buffering, and asynchronous writes\n * without blocking the main thread.\n *\n * ## Performance Characteristics\n *\n * - **High Performance**: Optimized for high-volume logging scenarios\n * - **Non-blocking**: Uses asynchronous I/O that doesn't block the main thread\n * - **Memory Efficient**: Automatic backpressure prevents memory buildup\n * - **Stream-based**: Leverages Node.js native stream optimizations\n *\n * ## When to Use\n *\n * Use this sink when you need:\n * - High-performance file logging for production applications\n * - Non-blocking I/O behavior for real-time applications\n * - Automatic backpressure handling for high-volume scenarios\n * - Simple file output without complex buffering configuration\n *\n * For more control over buffering behavior, consider using {@link getFileSink}\n * instead, which provides options for buffer size, flush intervals, and\n * non-blocking modes.\n *\n * ## Example\n *\n * ```typescript\n * import { configure } from \"@logtape/logtape\";\n * import { getStreamFileSink } from \"@logtape/file\";\n *\n * await configure({\n * sinks: {\n * file: getStreamFileSink(\"app.log\", {\n * highWaterMark: 32768 // 32KB buffer for high-volume logging\n * })\n * },\n * loggers: [\n * { category: [\"myapp\"], sinks: [\"file\"] }\n * ]\n * });\n * ```\n *\n * @param path The path to the file to write logs to. The file will be created\n * if it doesn't exist, or appended to if it does exist.\n * @param options Configuration options for the stream-based sink.\n * @returns A sink that writes formatted log records to the specified file.\n * The returned sink implements `Disposable` for proper resource cleanup.\n *\n * @since 1.0.0\n */\nexport function getStreamFileSink(\n path: string,\n options: StreamFileSinkOptions = {},\n): Sink & Disposable {\n const highWaterMark = options.highWaterMark ?? 16384;\n const formatter = options.formatter ?? defaultTextFormatter;\n\n // Create PassThrough stream for optimal performance\n const passThrough = new PassThrough({\n highWaterMark,\n objectMode: false,\n });\n\n // Create WriteStream immediately (not lazy)\n const writeStream = createWriteStream(path, { flags: \"a\" });\n\n // Pipe PassThrough to WriteStream for automatic backpressure handling\n passThrough.pipe(writeStream);\n\n let disposed = false;\n\n // Stream-based sink function for high performance\n const sink: Sink & Disposable = (record: LogRecord) => {\n if (disposed) return;\n\n // Direct write to PassThrough stream\n passThrough.write(formatter(record));\n };\n\n // Minimal disposal\n sink[Symbol.dispose] = () => {\n if (disposed) return;\n disposed = true;\n passThrough.end();\n writeStream.end();\n };\n\n return sink;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,SAAgB,kBACdA,MACAC,UAAiC,CAAE,GAChB;CACnB,MAAM,gBAAgB,QAAQ,iBAAiB;CAC/C,MAAM,YAAY,QAAQ,aAAa;CAGvC,MAAM,cAAc,IAAI,YAAY;EAClC;EACA,YAAY;CACb;CAGD,MAAM,cAAc,kBAAkB,MAAM,EAAE,OAAO,IAAK,EAAC;AAG3D,aAAY,KAAK,YAAY;CAE7B,IAAI,WAAW;CAGf,MAAMC,OAA0B,CAACC,WAAsB;AACrD,MAAI,SAAU;AAGd,cAAY,MAAM,UAAU,OAAO,CAAC;CACrC;AAGD,MAAK,OAAO,WAAW,MAAM;AAC3B,MAAI,SAAU;AACd,aAAW;AACX,cAAY,KAAK;AACjB,cAAY,KAAK;CAClB;AAED,QAAO;AACR"}
|