@logtape/file 0.10.0-dev.139 → 0.10.0-dev.146
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/esm/file/filesink.base.js +9 -2
- package/esm/logtape/formatter.js +4 -2
- package/package.json +1 -1
- package/script/file/filesink.base.js +9 -2
- package/script/logtape/formatter.js +4 -2
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_is_error.d.ts.map +1 -0
- package/types/deps/jsr.io/@std/assert/0.222.1/assert_throws.d.ts.map +1 -0
- package/types/file/filesink.base.d.ts +7 -2
- package/types/file/filesink.base.d.ts.map +1 -1
- package/types/logtape/formatter.d.ts +3 -2
- package/types/logtape/formatter.d.ts.map +1 -1
|
@@ -11,12 +11,19 @@ import { defaultTextFormatter, } from "../logtape/mod.js";
|
|
|
11
11
|
export function getBaseFileSink(path, options) {
|
|
12
12
|
const formatter = options.formatter ?? defaultTextFormatter;
|
|
13
13
|
const encoder = options.encoder ?? new TextEncoder();
|
|
14
|
-
|
|
14
|
+
let fd = options.lazy ? null : options.openSync(path);
|
|
15
15
|
const sink = (record) => {
|
|
16
|
+
if (fd === null) {
|
|
17
|
+
fd = options.openSync(path);
|
|
18
|
+
}
|
|
16
19
|
options.writeSync(fd, encoder.encode(formatter(record)));
|
|
17
20
|
options.flushSync(fd);
|
|
18
21
|
};
|
|
19
|
-
sink[Symbol.dispose] = () =>
|
|
22
|
+
sink[Symbol.dispose] = () => {
|
|
23
|
+
if (fd !== null) {
|
|
24
|
+
options.closeSync(fd);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
20
27
|
return sink;
|
|
21
28
|
}
|
|
22
29
|
/**
|
package/esm/logtape/formatter.js
CHANGED
|
@@ -80,7 +80,9 @@ export function getTextFormatter(options = {}) {
|
|
|
80
80
|
? (ts) => new Date(ts).toISOString().replace(/T.*/, "")
|
|
81
81
|
: options.timestamp === "rfc3339"
|
|
82
82
|
? (ts) => new Date(ts).toISOString()
|
|
83
|
-
: options.timestamp
|
|
83
|
+
: options.timestamp === "none" || options.timestamp === "disabled"
|
|
84
|
+
? () => null
|
|
85
|
+
: options.timestamp;
|
|
84
86
|
const categorySeparator = options.category ?? "·";
|
|
85
87
|
const valueRenderer = options.value ?? inspect;
|
|
86
88
|
const levelRenderer = options.level == null || options.level === "ABBR"
|
|
@@ -97,7 +99,7 @@ export function getTextFormatter(options = {}) {
|
|
|
97
99
|
? (level) => level.charAt(0)
|
|
98
100
|
: options.level;
|
|
99
101
|
const formatter = options.format ??
|
|
100
|
-
(({ timestamp, level, category, message }) => `${timestamp} [${level}] ${category}: ${message}`);
|
|
102
|
+
(({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
|
|
101
103
|
return (record) => {
|
|
102
104
|
let message = "";
|
|
103
105
|
for (let i = 0; i < record.message.length; i++) {
|
package/package.json
CHANGED
|
@@ -15,12 +15,19 @@ const mod_js_1 = require("../logtape/mod.js");
|
|
|
15
15
|
function getBaseFileSink(path, options) {
|
|
16
16
|
const formatter = options.formatter ?? mod_js_1.defaultTextFormatter;
|
|
17
17
|
const encoder = options.encoder ?? new TextEncoder();
|
|
18
|
-
|
|
18
|
+
let fd = options.lazy ? null : options.openSync(path);
|
|
19
19
|
const sink = (record) => {
|
|
20
|
+
if (fd === null) {
|
|
21
|
+
fd = options.openSync(path);
|
|
22
|
+
}
|
|
20
23
|
options.writeSync(fd, encoder.encode(formatter(record)));
|
|
21
24
|
options.flushSync(fd);
|
|
22
25
|
};
|
|
23
|
-
sink[Symbol.dispose] = () =>
|
|
26
|
+
sink[Symbol.dispose] = () => {
|
|
27
|
+
if (fd !== null) {
|
|
28
|
+
options.closeSync(fd);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
24
31
|
return sink;
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
@@ -89,7 +89,9 @@ function getTextFormatter(options = {}) {
|
|
|
89
89
|
? (ts) => new Date(ts).toISOString().replace(/T.*/, "")
|
|
90
90
|
: options.timestamp === "rfc3339"
|
|
91
91
|
? (ts) => new Date(ts).toISOString()
|
|
92
|
-
: options.timestamp
|
|
92
|
+
: options.timestamp === "none" || options.timestamp === "disabled"
|
|
93
|
+
? () => null
|
|
94
|
+
: options.timestamp;
|
|
93
95
|
const categorySeparator = options.category ?? "·";
|
|
94
96
|
const valueRenderer = options.value ?? inspect;
|
|
95
97
|
const levelRenderer = options.level == null || options.level === "ABBR"
|
|
@@ -106,7 +108,7 @@ function getTextFormatter(options = {}) {
|
|
|
106
108
|
? (level) => level.charAt(0)
|
|
107
109
|
: options.level;
|
|
108
110
|
const formatter = options.format ??
|
|
109
|
-
(({ timestamp, level, category, message }) => `${timestamp} [${level}] ${category}: ${message}`);
|
|
111
|
+
(({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
|
|
110
112
|
return (record) => {
|
|
111
113
|
let message = "";
|
|
112
114
|
for (let i = 0; i < record.message.length; i++) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert_is_error.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_is_error.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EACnD,KAAK,EAAE,OAAO,EAEd,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACtC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAC5B,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,CAmCpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert_throws.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_throws.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;AACX;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAClD,EAAE,EAAE,MAAM,OAAO,EAEjB,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EACrC,WAAW,CAAC,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,CAAC,CAAC"}
|
|
@@ -2,7 +2,12 @@ import { type Sink, type StreamSinkOptions } from "../logtape/mod.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Options for the {@link getBaseFileSink} function.
|
|
4
4
|
*/
|
|
5
|
-
export type FileSinkOptions = StreamSinkOptions
|
|
5
|
+
export type FileSinkOptions = StreamSinkOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* If `true`, the file is not opened until the first write. Defaults to `false`.
|
|
8
|
+
*/
|
|
9
|
+
lazy?: boolean;
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* A platform-specific file sink driver.
|
|
8
13
|
* @typeParam TFile The type of the file descriptor.
|
|
@@ -43,7 +48,7 @@ export declare function getBaseFileSink<TFile>(path: string, options: FileSinkOp
|
|
|
43
48
|
/**
|
|
44
49
|
* Options for the {@link getBaseRotatingFileSink} function.
|
|
45
50
|
*/
|
|
46
|
-
export interface RotatingFileSinkOptions extends FileSinkOptions {
|
|
51
|
+
export interface RotatingFileSinkOptions extends Omit<FileSinkOptions, "lazy"> {
|
|
47
52
|
/**
|
|
48
53
|
* The maximum bytes of the file before it is rotated. 1 MiB by default.
|
|
49
54
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesink.base.d.ts","sourceRoot":"","sources":["../../src/file/filesink.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,iBAAiB,EACvB,MAAM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A;KAAE,CAAC;IAEzC;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAC3C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,GAAG,sBAAsB,CAAC,KAAK,CAAC,GAC/D,IAAI,GAAG,UAAU,CAwCnB"}
|
|
@@ -16,7 +16,7 @@ export interface FormattedValues {
|
|
|
16
16
|
/**
|
|
17
17
|
* The formatted timestamp.
|
|
18
18
|
*/
|
|
19
|
-
timestamp: string;
|
|
19
|
+
timestamp: string | null;
|
|
20
20
|
/**
|
|
21
21
|
* The formatted log level.
|
|
22
22
|
*/
|
|
@@ -58,13 +58,14 @@ export interface TextFormatterOptions {
|
|
|
58
58
|
* (e.g., `"2023-11-14"`).
|
|
59
59
|
* - `"rfc3339"`: The date and time in RFC 3339 format
|
|
60
60
|
* (e.g., `"2023-11-14T22:13:20.000Z"`).
|
|
61
|
+
* - `"none"` or `"disabled"`: No displayment
|
|
61
62
|
*
|
|
62
63
|
* Alternatively, this can be a function that accepts a timestamp and returns
|
|
63
64
|
* a string.
|
|
64
65
|
*
|
|
65
66
|
* The default is `"date-time-timezone"`.
|
|
66
67
|
*/
|
|
67
|
-
timestamp?: "date-time-timezone" | "date-time-tz" | "date-time" | "time-timezone" | "time-tz" | "time" | "date" | "rfc3339" | ((ts: number) => string);
|
|
68
|
+
timestamp?: "date-time-timezone" | "date-time-tz" | "date-time" | "time-timezone" | "time-tz" | "time" | "date" | "rfc3339" | "none" | "disabled" | ((ts: number) => string | null);
|
|
68
69
|
/**
|
|
69
70
|
* The log level format. This can be one of the following:
|
|
70
71
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/logtape/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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