logroller 1.0.0
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/LICENSE +5 -0
- package/README.md +147 -0
- package/dist/index.cjs +875 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.esm.js +872 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
export type RotationReason = "time" | "size" | "manual";
|
|
3
|
+
export interface RotateFileStreamOptions {
|
|
4
|
+
/** Required. Must contain %DATE% — e.g. "logs/app-%DATE%.log" */
|
|
5
|
+
filename: string;
|
|
6
|
+
/** Tokens: YYYY YY MM DD HH mm ss. Default "YYYY-MM-DD". */
|
|
7
|
+
datePattern?: string;
|
|
8
|
+
/** gzip closed segments. Default false. */
|
|
9
|
+
zippedArchive?: boolean;
|
|
10
|
+
/** Roll when next write would exceed: 20 | "20m" | "1k" | "5g". 0/undefined = off. */
|
|
11
|
+
maxSize?: number | string;
|
|
12
|
+
/** Retention: "90d" (age) | 500 (count). Unset = never delete. */
|
|
13
|
+
maxFiles?: number | string;
|
|
14
|
+
/** Any IANA zone. Default "UTC". */
|
|
15
|
+
tz?: string;
|
|
16
|
+
/** "daily" | "1s" | "5m" | "2h" | ms number. Default "daily". */
|
|
17
|
+
frequency?: number | string;
|
|
18
|
+
/** Static virtual-clock shift in hours ("-6h", 1.5). TEST ONLY. */
|
|
19
|
+
addHours?: number | string;
|
|
20
|
+
/** Amount added to the clock every clockStepIntervalMs ("24h"). TEST ONLY. */
|
|
21
|
+
addHoursEveryMin?: number | string;
|
|
22
|
+
/** How often addHoursEveryMin applies. Default 60_000 ms. */
|
|
23
|
+
clockStepIntervalMs?: number;
|
|
24
|
+
/** Don't hold the process open via rotation timers. */
|
|
25
|
+
unrefTimers?: boolean;
|
|
26
|
+
/** Write <stem>_audit.json manifest. Default true. */
|
|
27
|
+
audit?: boolean;
|
|
28
|
+
/** Override manifest filename. */
|
|
29
|
+
auditFile?: string;
|
|
30
|
+
highWaterMark?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface RotatedInfo {
|
|
33
|
+
reason: RotationReason;
|
|
34
|
+
oldFile: string | null;
|
|
35
|
+
archive: string | null;
|
|
36
|
+
newFile: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ClockInfo {
|
|
39
|
+
addHours?: number | string;
|
|
40
|
+
addHoursEveryMin?: number | string;
|
|
41
|
+
offsetMs: number;
|
|
42
|
+
}
|
|
43
|
+
export interface RotateFileStreamEvents {
|
|
44
|
+
open: (file: string) => void;
|
|
45
|
+
rotated: (info: RotatedInfo) => void;
|
|
46
|
+
archive: (gzFile: string) => void;
|
|
47
|
+
deleted: (file: string) => void;
|
|
48
|
+
period: (stamp: string) => void;
|
|
49
|
+
clock: (info: ClockInfo) => void;
|
|
50
|
+
warn: (err: Error) => void;
|
|
51
|
+
error: (err: Error) => void;
|
|
52
|
+
close: () => void;
|
|
53
|
+
}
|
|
54
|
+
/** ◀ TS FIX: interface members SHADOW inherited Writable.on/emit.
|
|
55
|
+
* Add a generic string fallback so `.pipe()` stays structurally valid. */
|
|
56
|
+
export interface RotateFileStream {
|
|
57
|
+
on<E extends keyof RotateFileStreamEvents>(event: E, listener: RotateFileStreamEvents[E]): this;
|
|
58
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
59
|
+
once<E extends keyof RotateFileStreamEvents>(event: E, listener: RotateFileStreamEvents[E]): this;
|
|
60
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
61
|
+
emit<E extends keyof RotateFileStreamEvents>(event: E, ...args: Parameters<RotateFileStreamEvents[E]>): boolean;
|
|
62
|
+
emit(event: string, ...args: any[]): boolean;
|
|
63
|
+
}
|
|
64
|
+
interface ParsedMaxFiles {
|
|
65
|
+
days?: number;
|
|
66
|
+
count?: number;
|
|
67
|
+
}
|
|
68
|
+
type ParsedFrequency = {
|
|
69
|
+
type: "daily";
|
|
70
|
+
} | {
|
|
71
|
+
type: "interval";
|
|
72
|
+
ms: number;
|
|
73
|
+
};
|
|
74
|
+
export declare class RotateFileStream extends Writable {
|
|
75
|
+
readonly tz: string;
|
|
76
|
+
readonly template: string;
|
|
77
|
+
readonly dir: string;
|
|
78
|
+
readonly datePattern: string;
|
|
79
|
+
readonly zippedArchive: boolean;
|
|
80
|
+
readonly maxSize: number;
|
|
81
|
+
readonly maxFiles: ParsedMaxFiles | null;
|
|
82
|
+
readonly freq: ParsedFrequency;
|
|
83
|
+
readonly unrefTimers: boolean;
|
|
84
|
+
private readonly _tL;
|
|
85
|
+
private readonly _tMid;
|
|
86
|
+
private readonly _tExt;
|
|
87
|
+
private readonly _rxFor;
|
|
88
|
+
private readonly _rxActive;
|
|
89
|
+
private readonly _auditEnabled;
|
|
90
|
+
private readonly _auditPath;
|
|
91
|
+
private readonly _bootId;
|
|
92
|
+
private _offsetMs;
|
|
93
|
+
private _stepMs;
|
|
94
|
+
private _bumpEvery;
|
|
95
|
+
private _curStamp;
|
|
96
|
+
private _index;
|
|
97
|
+
private _ws;
|
|
98
|
+
private _path;
|
|
99
|
+
private _bytes;
|
|
100
|
+
private _timer;
|
|
101
|
+
private _bumpTimer;
|
|
102
|
+
private _ended;
|
|
103
|
+
private _tail;
|
|
104
|
+
private _audit;
|
|
105
|
+
constructor(opts?: Partial<RotateFileStreamOptions>);
|
|
106
|
+
get filename(): string | null;
|
|
107
|
+
get currentIndex(): number;
|
|
108
|
+
private _now;
|
|
109
|
+
rotateNow(): Promise<void>;
|
|
110
|
+
/** Apply one virtual-clock step immediately (test helper). */
|
|
111
|
+
advanceClock(): Promise<void>;
|
|
112
|
+
private _resetAuditObject;
|
|
113
|
+
private _loadAudit;
|
|
114
|
+
private _saveAudit;
|
|
115
|
+
private _pruneAuditFiles;
|
|
116
|
+
private _aevent;
|
|
117
|
+
private _setActivePointer;
|
|
118
|
+
private _demoteZombieActives;
|
|
119
|
+
private _reconcileWithDisk;
|
|
120
|
+
private _repairInterruptedGzips;
|
|
121
|
+
private _finishArchivedRecord;
|
|
122
|
+
_write(chunk: any, encoding: BufferEncoding, cb: (error?: Error | null) => void): void;
|
|
123
|
+
_final(cb: (error?: Error | null) => void): void;
|
|
124
|
+
destroy(...args: Parameters<Writable["destroy"]>): this;
|
|
125
|
+
private _job;
|
|
126
|
+
private _stampNow;
|
|
127
|
+
private _resolveName;
|
|
128
|
+
private _recoverIndexFor;
|
|
129
|
+
private _ensureOpen;
|
|
130
|
+
private _rotate;
|
|
131
|
+
private _hasContent;
|
|
132
|
+
private _armTimer;
|
|
133
|
+
private _armBump;
|
|
134
|
+
private _stopBump;
|
|
135
|
+
private _applyBump;
|
|
136
|
+
private _stopTimer;
|
|
137
|
+
private _retire;
|
|
138
|
+
}
|
|
139
|
+
export declare function createStream(options: RotateFileStreamOptions): RotateFileStream;
|
|
140
|
+
export {};
|