@trebired/logger 2.5.0 → 2.5.3
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/CHANGELOG.md +10 -1
- package/dist/backend/utils/normalize.d.ts +2 -0
- package/dist/backend/utils/normalize.d.ts.map +1 -0
- package/dist/backend/utils/normalize.js +4 -0
- package/dist/backend/utils/normalize.js.map +1 -0
- package/dist/backend/utils/object.d.ts +3 -0
- package/dist/backend/utils/object.d.ts.map +1 -0
- package/dist/backend/utils/object.js +12 -0
- package/dist/backend/utils/object.js.map +1 -0
- package/dist/backend/utils/time.d.ts +3 -0
- package/dist/backend/utils/time.d.ts.map +1 -0
- package/dist/backend/utils/time.js +7 -0
- package/dist/backend/utils/time.js.map +1 -0
- package/dist/browser/console_transport.d.ts.map +1 -1
- package/dist/browser/console_transport.js.map +1 -1
- package/dist/browser/create_log.d.ts.map +1 -1
- package/dist/browser/create_log.js.map +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/react.d.ts.map +1 -1
- package/dist/config/console_visibility.js.map +1 -1
- package/dist/core/create_log/api.d.ts +6 -0
- package/dist/core/create_log/api.d.ts.map +1 -0
- package/dist/core/create_log/api.js +182 -0
- package/dist/core/create_log/api.js.map +1 -0
- package/dist/core/create_log/finalize.d.ts +16 -0
- package/dist/core/create_log/finalize.d.ts.map +1 -0
- package/dist/core/create_log/finalize.js +197 -0
- package/dist/core/create_log/finalize.js.map +1 -0
- package/dist/core/create_log/runtime.d.ts +44 -0
- package/dist/core/create_log/runtime.d.ts.map +1 -0
- package/dist/core/create_log/runtime.js +212 -0
- package/dist/core/create_log/runtime.js.map +1 -0
- package/dist/core/create_log.d.ts.map +1 -1
- package/dist/core/create_log.js +15 -387
- package/dist/core/create_log.js.map +1 -1
- package/dist/core/shared.d.ts.map +1 -1
- package/dist/core/shared.js +119 -58
- package/dist/core/shared.js.map +1 -1
- package/dist/format/console.d.ts.map +1 -1
- package/dist/format/console.js.map +1 -1
- package/dist/format/options.d.ts.map +1 -1
- package/dist/format/options.js.map +1 -1
- package/dist/frontend/js/utils/text.d.ts +2 -0
- package/dist/frontend/js/utils/text.d.ts.map +1 -0
- package/dist/frontend/js/utils/text.js +4 -0
- package/dist/frontend/js/utils/text.js.map +1 -0
- package/dist/levels/index.d.ts.map +1 -1
- package/dist/levels/index.js.map +1 -1
- package/dist/metadata/process.d.ts.map +1 -1
- package/dist/metadata/process.js.map +1 -1
- package/dist/middleware/request.d.ts.map +1 -1
- package/dist/middleware/request.js.map +1 -1
- package/dist/storage/backend/js.d.ts.map +1 -1
- package/dist/storage/backend/js.js +44 -26
- package/dist/storage/backend/js.js.map +1 -1
- package/dist/storage/backend/native.d.ts.map +1 -1
- package/dist/storage/backend/types.d.ts.map +1 -1
- package/dist/storage/export.d.ts.map +1 -1
- package/dist/storage/export.js.map +1 -1
- package/dist/storage/names.d.ts.map +1 -1
- package/dist/storage/names.js.map +1 -1
- package/dist/storage/options.d.ts.map +1 -1
- package/dist/storage/options.js.map +1 -1
- package/dist/storage/partitions/delete.d.ts.map +1 -1
- package/dist/storage/partitions/delete.js.map +1 -1
- package/dist/storage/partitions/files.d.ts.map +1 -1
- package/dist/storage/partitions/files.js.map +1 -1
- package/dist/storage/partitions/internal.d.ts.map +1 -1
- package/dist/storage/partitions/internal.js.map +1 -1
- package/dist/storage/partitions/markers.js.map +1 -1
- package/dist/storage/partitions/public.d.ts.map +1 -1
- package/dist/storage/partitions/public.js.map +1 -1
- package/dist/storage/partitions/records.d.ts.map +1 -1
- package/dist/storage/partitions/records.js.map +1 -1
- package/dist/storage/partitions/rewrite.d.ts.map +1 -1
- package/dist/storage/partitions/rewrite.js.map +1 -1
- package/dist/storage/partitions/transforms.d.ts.map +1 -1
- package/dist/storage/partitions/transforms.js.map +1 -1
- package/dist/storage/query/rows.d.ts.map +1 -1
- package/dist/storage/query/shared.d.ts.map +1 -1
- package/dist/storage/query/shared.js.map +1 -1
- package/dist/storage/query/summary.d.ts.map +1 -1
- package/dist/storage/query/summary.js.map +1 -1
- package/dist/storage/query.d.ts.map +1 -1
- package/dist/storage/query.js.map +1 -1
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/storage/retention.js +30 -19
- package/dist/storage/retention.js.map +1 -1
- package/dist/storage/walk.js.map +1 -1
- package/dist/storage/write.d.ts.map +1 -1
- package/dist/storage/write.js.map +1 -1
- package/dist/utils/values.d.ts +4 -5
- package/dist/utils/values.d.ts.map +1 -1
- package/dist/utils/values.js +4 -5
- package/dist/utils/values.js.map +1 -1
- package/native/linux-x64-gnu.node +0 -0
- package/package.json +124 -60
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/native/linux-arm64-gnu.node +0 -0
package/dist/core/create_log.js
CHANGED
|
@@ -1,393 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { logStream } from "../stream/index.js";
|
|
9
|
-
import { activeStorageBackendNotice } from "../storage/backend/index.js";
|
|
10
|
-
import { exportPartition as exportStoredPartition, exportPartitions as exportStoredPartitions } from "../storage/export.js";
|
|
11
|
-
import { normalizePartitionKey, sanitizePartitionName } from "../storage/names.js";
|
|
12
|
-
import { deleteNonCurrentTemporaryPartitions } from "../storage/partitions/delete.js";
|
|
13
|
-
import { createPartitionError, isPartitionError } from "../storage/partitions/errors.js";
|
|
14
|
-
import { getPartitionInfo as getStoredPartitionInfo, listPartitions as listStoredPartitions, mergePartition, renamePartition, touchPartitionMarkerSync, } from "../storage/partitions.js";
|
|
15
|
-
import { getLogsForDir } from "../storage/query.js";
|
|
16
|
-
import { normalizeRetentionOptions, normalizeWriteOptions } from "../storage/options.js";
|
|
17
|
-
import { FileWriter } from "../storage/write.js";
|
|
18
|
-
import { normalizeTimeZone } from "../utils/datetime.js";
|
|
19
|
-
import { maybeShowNodeRuntimeNotice, writePackageNotice } from "../utils/runtime.js";
|
|
20
|
-
import { toString } from "../utils/values.js";
|
|
21
|
-
let packageGreetingShown = false;
|
|
22
|
-
let storageBackendNoticeShown = false;
|
|
23
|
-
const activeTemporaryPartitionsByDir = new Map();
|
|
1
|
+
import { createBaseLogApi, createCreateLogRuntime, } from "./create_log/runtime.js";
|
|
2
|
+
import { attachLogApi, maybeShowInitializationNotices, } from "./create_log/api.js";
|
|
3
|
+
const sharedState = {
|
|
4
|
+
packageGreetingShown: false,
|
|
5
|
+
storageBackendNoticeShown: false,
|
|
6
|
+
activeTemporaryPartitionsByDir: new Map(),
|
|
7
|
+
};
|
|
24
8
|
function resetCreateLogStateForTests() {
|
|
25
|
-
packageGreetingShown = false;
|
|
26
|
-
storageBackendNoticeShown = false;
|
|
27
|
-
activeTemporaryPartitionsByDir.clear();
|
|
28
|
-
}
|
|
29
|
-
function safeResolveDir(value) {
|
|
30
|
-
const raw = toString(value);
|
|
31
|
-
return raw ? path.resolve(raw) : "";
|
|
32
|
-
}
|
|
33
|
-
function cleanupErrorMessage(error) {
|
|
34
|
-
return error instanceof Error ? error.message : String(error);
|
|
35
|
-
}
|
|
36
|
-
function resolvePartitionExistsPolicy(options, fallback) {
|
|
37
|
-
if (options && typeof options === "object" && options.ifExists)
|
|
38
|
-
return options.ifExists;
|
|
39
|
-
if (options && typeof options === "object" && "merge" in options && options.merge === true)
|
|
40
|
-
return "merge";
|
|
41
|
-
return fallback;
|
|
9
|
+
sharedState.packageGreetingShown = false;
|
|
10
|
+
sharedState.storageBackendNoticeShown = false;
|
|
11
|
+
sharedState.activeTemporaryPartitionsByDir.clear();
|
|
42
12
|
}
|
|
43
13
|
function createLog(options = {}) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (consoleVisibility.warning)
|
|
50
|
-
writePackageNotice(consoleVisibility.warning);
|
|
51
|
-
const timeZone = normalizeTimeZone(cfg.timeZone);
|
|
52
|
-
let activePartition = normalizePartitionKey(cfg.partition) || null;
|
|
53
|
-
let activeTemporary = cfg.temporaryPartition === true;
|
|
54
|
-
let bypassConsoleVisibility = false;
|
|
55
|
-
const writer = new FileWriter({
|
|
56
|
-
dir: safeResolveDir(cfg.dir),
|
|
57
|
-
save: typeof cfg.save === "boolean" ? cfg.save : Boolean(toString(cfg.dir)),
|
|
58
|
-
write: normalizeWriteOptions(cfg.write),
|
|
59
|
-
retention: normalizeRetentionOptions(cfg.retention),
|
|
60
|
-
timeZone,
|
|
61
|
-
onError: (message) => writeConsole("stderr", message),
|
|
62
|
-
});
|
|
63
|
-
let registeredTemporaryPartition = null;
|
|
64
|
-
function withConsoleVisibilityBypass(fn) {
|
|
65
|
-
bypassConsoleVisibility = true;
|
|
66
|
-
try {
|
|
67
|
-
return fn();
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
bypassConsoleVisibility = false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function unregisterTemporaryPartition() {
|
|
74
|
-
if (!registeredTemporaryPartition)
|
|
75
|
-
return;
|
|
76
|
-
const current = activeTemporaryPartitionsByDir.get(registeredTemporaryPartition.dir);
|
|
77
|
-
if (current) {
|
|
78
|
-
current.delete(registeredTemporaryPartition.partition);
|
|
79
|
-
if (current.size === 0)
|
|
80
|
-
activeTemporaryPartitionsByDir.delete(registeredTemporaryPartition.dir);
|
|
81
|
-
}
|
|
82
|
-
registeredTemporaryPartition = null;
|
|
83
|
-
}
|
|
84
|
-
function registerTemporaryPartition() {
|
|
85
|
-
unregisterTemporaryPartition();
|
|
86
|
-
if (!activeTemporary || !activePartition || !writer.isSavingEnabled() || !writer.getDir())
|
|
87
|
-
return;
|
|
88
|
-
const dir = writer.getDir();
|
|
89
|
-
const current = activeTemporaryPartitionsByDir.get(dir) || new Set();
|
|
90
|
-
current.add(activePartition);
|
|
91
|
-
activeTemporaryPartitionsByDir.set(dir, current);
|
|
92
|
-
registeredTemporaryPartition = { dir, partition: activePartition };
|
|
93
|
-
}
|
|
94
|
-
function keepTemporaryPartitions(dir) {
|
|
95
|
-
return Array.from(activeTemporaryPartitionsByDir.get(dir) || []);
|
|
96
|
-
}
|
|
97
|
-
async function cleanupTemporaryPartitions(dir = writer.getDir()) {
|
|
98
|
-
if (!writer.isSavingEnabled() || !dir)
|
|
99
|
-
return;
|
|
100
|
-
await deleteNonCurrentTemporaryPartitions(dir, keepTemporaryPartitions(dir));
|
|
101
|
-
}
|
|
102
|
-
function scheduleTemporaryPartitionCleanup(dir = writer.getDir()) {
|
|
103
|
-
if (!writer.isSavingEnabled() || !dir)
|
|
104
|
-
return;
|
|
105
|
-
void cleanupTemporaryPartitions(dir).catch((error) => {
|
|
106
|
-
writeConsole("stderr", `[trebired.logger] temporary partition cleanup failed: ${cleanupErrorMessage(error)}`);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async function applyActivePartition(nextPartition, nextTemporary) {
|
|
110
|
-
unregisterTemporaryPartition();
|
|
111
|
-
activePartition = nextPartition;
|
|
112
|
-
activeTemporary = nextTemporary;
|
|
113
|
-
if (activePartition && writer.isSavingEnabled() && writer.getDir()) {
|
|
114
|
-
touchPartitionMarkerSync(writer.getDir(), activePartition, {
|
|
115
|
-
temporary: activeTemporary,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
registerTemporaryPartition();
|
|
119
|
-
await cleanupTemporaryPartitions();
|
|
120
|
-
}
|
|
121
|
-
function createFinalizePartitionResult(args) {
|
|
122
|
-
return {
|
|
123
|
-
partition: args.partition,
|
|
124
|
-
previousPartition: args.previousPartition,
|
|
125
|
-
action: args.action,
|
|
126
|
-
sourceExisted: args.sourceExisted,
|
|
127
|
-
targetExisted: args.targetExisted,
|
|
128
|
-
temporaryBefore: args.temporaryBefore,
|
|
129
|
-
temporaryAfter: false,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async function finalizeActivePartition(partition, options, fallbackPolicy) {
|
|
133
|
-
if (!activePartition)
|
|
134
|
-
throw createPartitionError("partition-not-set");
|
|
135
|
-
const nextPartition = sanitizePartitionName(partition);
|
|
136
|
-
const previousPartition = activePartition;
|
|
137
|
-
const temporaryBefore = activeTemporary;
|
|
138
|
-
const ifExists = resolvePartitionExistsPolicy(options, fallbackPolicy);
|
|
139
|
-
await writer.flush();
|
|
140
|
-
if (!writer.isSavingEnabled() || !writer.getDir()) {
|
|
141
|
-
if (nextPartition === activePartition) {
|
|
142
|
-
const action = activeTemporary ? "marked-permanent" : "already-finalized";
|
|
143
|
-
activeTemporary = false;
|
|
144
|
-
return createFinalizePartitionResult({
|
|
145
|
-
action,
|
|
146
|
-
partition: nextPartition,
|
|
147
|
-
previousPartition,
|
|
148
|
-
sourceExisted: false,
|
|
149
|
-
targetExisted: false,
|
|
150
|
-
temporaryBefore,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
activePartition = nextPartition;
|
|
154
|
-
activeTemporary = false;
|
|
155
|
-
return createFinalizePartitionResult({
|
|
156
|
-
action: "activated-target",
|
|
157
|
-
partition: nextPartition,
|
|
158
|
-
previousPartition,
|
|
159
|
-
sourceExisted: false,
|
|
160
|
-
targetExisted: false,
|
|
161
|
-
temporaryBefore,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
const dir = writer.getDir();
|
|
165
|
-
if (nextPartition === activePartition) {
|
|
166
|
-
touchPartitionMarkerSync(dir, nextPartition, { temporary: false });
|
|
167
|
-
unregisterTemporaryPartition();
|
|
168
|
-
activeTemporary = false;
|
|
169
|
-
await cleanupTemporaryPartitions();
|
|
170
|
-
return createFinalizePartitionResult({
|
|
171
|
-
action: temporaryBefore ? "marked-permanent" : "already-finalized",
|
|
172
|
-
partition: nextPartition,
|
|
173
|
-
previousPartition,
|
|
174
|
-
sourceExisted: true,
|
|
175
|
-
targetExisted: true,
|
|
176
|
-
temporaryBefore,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
let sourceInfo = await getStoredPartitionInfo(dir, activePartition);
|
|
180
|
-
let targetInfo = await getStoredPartitionInfo(dir, nextPartition);
|
|
181
|
-
const initialSourceExisted = Boolean(sourceInfo);
|
|
182
|
-
const initialTargetExisted = Boolean(targetInfo);
|
|
183
|
-
const activateTarget = async (action) => {
|
|
184
|
-
await applyActivePartition(nextPartition, false);
|
|
185
|
-
return createFinalizePartitionResult({
|
|
186
|
-
action,
|
|
187
|
-
partition: nextPartition,
|
|
188
|
-
previousPartition,
|
|
189
|
-
sourceExisted: initialSourceExisted,
|
|
190
|
-
targetExisted: initialTargetExisted,
|
|
191
|
-
temporaryBefore,
|
|
192
|
-
});
|
|
193
|
-
};
|
|
194
|
-
if (!sourceInfo) {
|
|
195
|
-
if (targetInfo) {
|
|
196
|
-
if (ifExists === "error") {
|
|
197
|
-
throw createPartitionError("partition-already-exists", { partition: nextPartition });
|
|
198
|
-
}
|
|
199
|
-
await applyActivePartition(nextPartition, false);
|
|
200
|
-
return createFinalizePartitionResult({
|
|
201
|
-
action: ifExists === "switch" ? "switched" : "activated-target",
|
|
202
|
-
partition: nextPartition,
|
|
203
|
-
previousPartition,
|
|
204
|
-
sourceExisted: false,
|
|
205
|
-
targetExisted: true,
|
|
206
|
-
temporaryBefore,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
await applyActivePartition(nextPartition, false);
|
|
210
|
-
return createFinalizePartitionResult({
|
|
211
|
-
action: "activated-target",
|
|
212
|
-
partition: nextPartition,
|
|
213
|
-
previousPartition,
|
|
214
|
-
sourceExisted: false,
|
|
215
|
-
targetExisted: false,
|
|
216
|
-
temporaryBefore,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (targetInfo) {
|
|
220
|
-
if (ifExists === "switch") {
|
|
221
|
-
return activateTarget("switched");
|
|
222
|
-
}
|
|
223
|
-
if (ifExists === "merge") {
|
|
224
|
-
await mergePartition(dir, { from: activePartition, to: nextPartition });
|
|
225
|
-
sourceInfo = await getStoredPartitionInfo(dir, activePartition);
|
|
226
|
-
targetInfo = await getStoredPartitionInfo(dir, nextPartition);
|
|
227
|
-
return activateTarget("merged");
|
|
228
|
-
}
|
|
229
|
-
throw createPartitionError("partition-already-exists", { partition: nextPartition });
|
|
230
|
-
}
|
|
231
|
-
try {
|
|
232
|
-
await renamePartition(dir, { from: activePartition, to: nextPartition });
|
|
233
|
-
sourceInfo = await getStoredPartitionInfo(dir, activePartition);
|
|
234
|
-
targetInfo = await getStoredPartitionInfo(dir, nextPartition);
|
|
235
|
-
return activateTarget("renamed");
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
if (!isPartitionError(error, "partition-already-exists"))
|
|
239
|
-
throw error;
|
|
240
|
-
sourceInfo = await getStoredPartitionInfo(dir, activePartition);
|
|
241
|
-
targetInfo = await getStoredPartitionInfo(dir, nextPartition);
|
|
242
|
-
if (!targetInfo)
|
|
243
|
-
throw error;
|
|
244
|
-
if (ifExists === "switch") {
|
|
245
|
-
return activateTarget("switched");
|
|
246
|
-
}
|
|
247
|
-
if (ifExists === "merge" && sourceInfo) {
|
|
248
|
-
await mergePartition(dir, { from: activePartition, to: nextPartition });
|
|
249
|
-
await applyActivePartition(nextPartition, false);
|
|
250
|
-
return createFinalizePartitionResult({
|
|
251
|
-
action: "merged",
|
|
252
|
-
partition: nextPartition,
|
|
253
|
-
previousPartition,
|
|
254
|
-
sourceExisted: true,
|
|
255
|
-
targetExisted: true,
|
|
256
|
-
temporaryBefore,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (activePartition && activeTemporary && writer.isSavingEnabled() && writer.getDir()) {
|
|
263
|
-
touchPartitionMarkerSync(writer.getDir(), activePartition, { temporary: true });
|
|
264
|
-
}
|
|
265
|
-
registerTemporaryPartition();
|
|
266
|
-
if (writer.isSavingEnabled() && writer.getDir())
|
|
267
|
-
scheduleTemporaryPartitionCleanup();
|
|
268
|
-
const { api: baseApi } = createCommonLogger({
|
|
269
|
-
levels,
|
|
270
|
-
minLevel: cfg.minLevel,
|
|
271
|
-
defaultSource: cfg.source,
|
|
272
|
-
serializers: cfg.serializers,
|
|
273
|
-
redact: cfg.redact,
|
|
274
|
-
sample: cfg.sample,
|
|
275
|
-
getPartition: () => activePartition,
|
|
276
|
-
writeEntry(entry, levelConfig) {
|
|
277
|
-
if (consoleOptions.enabled && (bypassConsoleVisibility || !consoleVisibility.shouldHide(entry.group))) {
|
|
278
|
-
writeConsole(levelConfig.stream, formatConsole(entry, levelConfig, consoleOptions, timeZone));
|
|
279
|
-
}
|
|
280
|
-
writer.write(entry);
|
|
281
|
-
try {
|
|
282
|
-
logStream.emit("log", entry, { runtime: "server", dir: writer.getDir() });
|
|
283
|
-
}
|
|
284
|
-
catch { }
|
|
285
|
-
},
|
|
286
|
-
flush() {
|
|
287
|
-
return writer.flush();
|
|
288
|
-
},
|
|
289
|
-
close() {
|
|
290
|
-
return writer.close();
|
|
291
|
-
},
|
|
292
|
-
getStats() {
|
|
293
|
-
return writer.getStats();
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
const api = baseApi;
|
|
297
|
-
Object.assign(api, {
|
|
298
|
-
getDir() {
|
|
299
|
-
return writer.getDir();
|
|
300
|
-
},
|
|
301
|
-
setDir(nextDir) {
|
|
302
|
-
const previousDir = writer.getDir();
|
|
303
|
-
unregisterTemporaryPartition();
|
|
304
|
-
writer.setDir(safeResolveDir(nextDir));
|
|
305
|
-
if (activePartition && activeTemporary && writer.isSavingEnabled() && writer.getDir()) {
|
|
306
|
-
touchPartitionMarkerSync(writer.getDir(), activePartition, { temporary: true });
|
|
307
|
-
}
|
|
308
|
-
registerTemporaryPartition();
|
|
309
|
-
if (previousDir && previousDir !== writer.getDir())
|
|
310
|
-
scheduleTemporaryPartitionCleanup(previousDir);
|
|
311
|
-
if (writer.isSavingEnabled() && writer.getDir())
|
|
312
|
-
scheduleTemporaryPartitionCleanup();
|
|
313
|
-
},
|
|
314
|
-
getPartition() {
|
|
315
|
-
return activePartition;
|
|
316
|
-
},
|
|
317
|
-
async setPartition(partition, options) {
|
|
318
|
-
const hasTemporary = Object.prototype.hasOwnProperty.call(options || {}, "temporary");
|
|
319
|
-
const nextPartition = partition == null ? null : sanitizePartitionName(String(partition));
|
|
320
|
-
const samePartition = nextPartition === activePartition;
|
|
321
|
-
const nextTemporary = nextPartition
|
|
322
|
-
? (hasTemporary ? options?.temporary === true : (samePartition ? activeTemporary : false))
|
|
323
|
-
: false;
|
|
324
|
-
await writer.flush();
|
|
325
|
-
await applyActivePartition(nextPartition, nextTemporary);
|
|
326
|
-
},
|
|
327
|
-
async finalizePartition(partition, options) {
|
|
328
|
-
return finalizeActivePartition(partition, options, "merge");
|
|
329
|
-
},
|
|
330
|
-
async promotePartition(partition, options) {
|
|
331
|
-
return finalizeActivePartition(partition, options, "error");
|
|
332
|
-
},
|
|
333
|
-
async listPartitions() {
|
|
334
|
-
return listStoredPartitions(writer.getDir());
|
|
335
|
-
},
|
|
336
|
-
async exportPartition(partitionOrOptions, maybeOptions) {
|
|
337
|
-
await writer.flush();
|
|
338
|
-
const hasPartitionArg = typeof partitionOrOptions === "string";
|
|
339
|
-
const partition = hasPartitionArg ? sanitizePartitionName(partitionOrOptions) : activePartition;
|
|
340
|
-
const options = (hasPartitionArg
|
|
341
|
-
? maybeOptions
|
|
342
|
-
: (partitionOrOptions && typeof partitionOrOptions === "object" ? partitionOrOptions : maybeOptions)) || {};
|
|
343
|
-
if (!partition)
|
|
344
|
-
throw createPartitionError("partition-not-set");
|
|
345
|
-
return exportStoredPartition(writer.getDir(), partition, options);
|
|
346
|
-
},
|
|
347
|
-
async exportPartitions(options) {
|
|
348
|
-
await writer.flush();
|
|
349
|
-
return exportStoredPartitions(writer.getDir(), options || {});
|
|
350
|
-
},
|
|
351
|
-
async getPartitionInfo(partition) {
|
|
352
|
-
const target = partition == null ? activePartition : sanitizePartitionName(partition);
|
|
353
|
-
if (!target)
|
|
354
|
-
return null;
|
|
355
|
-
return getStoredPartitionInfo(writer.getDir(), target);
|
|
356
|
-
},
|
|
357
|
-
async getAllLogs(options) {
|
|
358
|
-
await writer.flush();
|
|
359
|
-
const query = {
|
|
360
|
-
...(options || {}),
|
|
361
|
-
levels,
|
|
362
|
-
};
|
|
363
|
-
if (Object.prototype.hasOwnProperty.call(options || {}, "partition"))
|
|
364
|
-
query.partition = options?.partition ?? null;
|
|
365
|
-
else if (activePartition)
|
|
366
|
-
query.partition = activePartition;
|
|
367
|
-
return getLogsForDir(writer.getDir(), query);
|
|
368
|
-
},
|
|
369
|
-
async getAllLogsAcrossPartitions(options) {
|
|
370
|
-
await writer.flush();
|
|
371
|
-
return getLogsForDir(writer.getDir(), { ...(options || {}), acrossPartitions: true, levels });
|
|
372
|
-
},
|
|
373
|
-
async close() {
|
|
374
|
-
const cleanupDir = writer.getDir();
|
|
375
|
-
unregisterTemporaryPartition();
|
|
376
|
-
await writer.close();
|
|
377
|
-
await cleanupTemporaryPartitions(cleanupDir);
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
api.requestLogger = buildRequestMiddleware(api, cfg.request);
|
|
381
|
-
if (cfg.quiet !== true && !packageGreetingShown) {
|
|
382
|
-
packageGreetingShown = true;
|
|
383
|
-
withConsoleVisibilityBypass(() => {
|
|
384
|
-
api.success("logger.initialize", "@trebired/logger initialized");
|
|
385
|
-
if (!storageBackendNoticeShown) {
|
|
386
|
-
storageBackendNoticeShown = true;
|
|
387
|
-
api.info("logger.initialize", activeStorageBackendNotice());
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
}
|
|
14
|
+
const runtime = createCreateLogRuntime(options, sharedState);
|
|
15
|
+
runtime.initializeTemporaryPartitionState();
|
|
16
|
+
const api = createBaseLogApi(runtime);
|
|
17
|
+
attachLogApi(api, runtime);
|
|
18
|
+
maybeShowInitializationNotices(api, runtime, sharedState);
|
|
391
19
|
return api;
|
|
392
20
|
}
|
|
393
21
|
export { createLog, resetCreateLogStateForTests };
|
|
@@ -1 +1 @@
|
|
|
1
|
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GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3B,8BAA8B,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAE1D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/core/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/core/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGxF,QAAA,MAAM,aAAa,YAAY,CAAC;AAEhC,KAAK,mBAAmB,CAAC,MAAM,IAAI;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IAC1D,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACnC,UAAU,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,KAAK,IAAI,CAAC;IACnE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,EAAE,MAAM,MAAM,CAAC;CACxB,CAAC;AAEF,iBAAS,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAE,OAAc,GAAG,SAAS,CAOzE;AAED,iBAAS,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM;;;;EASlF;AAED,iBAAS,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAgBlG;AAED,iBAAS,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC;;uBAyDxD,MAAM,cACN,OAAO,gBACL,OAAO,kBACL,OAAO,gBACT,OAAO,CAAC,SAAS,CAAC,KAC/B,IAAI;EAlBR;AAmOD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;AAChG,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/core/shared.js
CHANGED
|
@@ -50,94 +50,155 @@ function createCommonLogger(options) {
|
|
|
50
50
|
const defaultMetadata = asObject(options.defaultMetadata);
|
|
51
51
|
let enabled = true;
|
|
52
52
|
let closed = false;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const emit = createEmitter({
|
|
54
|
+
defaultGroup,
|
|
55
|
+
defaultMetadata,
|
|
56
|
+
defaultSource,
|
|
57
|
+
enabled: () => enabled,
|
|
58
|
+
closed: () => closed,
|
|
59
|
+
levels,
|
|
60
|
+
options,
|
|
61
|
+
threshold,
|
|
62
|
+
});
|
|
63
|
+
const bindGroup = createGroupBinder({
|
|
64
|
+
defaultGroup,
|
|
65
|
+
defaultSource,
|
|
66
|
+
levels,
|
|
67
|
+
emit,
|
|
68
|
+
});
|
|
69
|
+
const api = createLoggerApi({
|
|
70
|
+
bindGroup,
|
|
71
|
+
defaultGroup,
|
|
72
|
+
defaultSource,
|
|
73
|
+
emit,
|
|
74
|
+
options,
|
|
75
|
+
setClosed(value) {
|
|
76
|
+
closed = value;
|
|
77
|
+
},
|
|
78
|
+
setEnabled(value) {
|
|
79
|
+
enabled = value;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
attachLevelLoggers(api, levels, defaultGroup, emit);
|
|
83
|
+
return {
|
|
84
|
+
api,
|
|
85
|
+
emit,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createEmitter(args) {
|
|
89
|
+
return function emit(levelInput, groupInput, messageInput, metadataInput, originInput) {
|
|
90
|
+
if (!args.enabled() || args.closed())
|
|
59
91
|
return;
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
message,
|
|
75
|
-
origin: buildOrigin(originSource, originInstance),
|
|
76
|
-
};
|
|
77
|
-
if (typeof options.getPartition === "function")
|
|
78
|
-
entry.partition = options.getPartition() ?? null;
|
|
79
|
-
if (Object.keys(metadata).length)
|
|
80
|
-
entry.metadata = metadata;
|
|
81
|
-
if (!shouldKeepSample(entry, options.sample))
|
|
92
|
+
const prepared = prepareEntry({
|
|
93
|
+
defaultGroup: args.defaultGroup,
|
|
94
|
+
defaultMetadata: args.defaultMetadata,
|
|
95
|
+
defaultSource: args.defaultSource,
|
|
96
|
+
groupInput,
|
|
97
|
+
levels: args.levels,
|
|
98
|
+
messageInput,
|
|
99
|
+
metadataInput,
|
|
100
|
+
options: args.options,
|
|
101
|
+
originInput,
|
|
102
|
+
threshold: args.threshold,
|
|
103
|
+
levelInput,
|
|
104
|
+
});
|
|
105
|
+
if (!prepared || !shouldKeepSample(prepared.entry, args.options.sample)) {
|
|
82
106
|
return;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
}
|
|
108
|
+
args.options.writeEntry(prepared.entry, prepared.levelConfig);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function createGroupBinder(args) {
|
|
112
|
+
return function bindGroup(groupName, originInput, extraMetadata) {
|
|
113
|
+
const boundGroup = normGroup(groupName || args.defaultGroup).key;
|
|
87
114
|
const mergedExtraMetadata = asObject(extraMetadata);
|
|
88
115
|
const grouped = {};
|
|
89
|
-
for (const level of Object.keys(levels)) {
|
|
90
|
-
grouped[level] = (message, metadata) => emit(level, boundGroup, message, { ...mergedExtraMetadata, ...asObject(metadata) }, originInput);
|
|
116
|
+
for (const level of Object.keys(args.levels)) {
|
|
117
|
+
grouped[level] = (message, metadata) => args.emit(level, boundGroup, message, { ...mergedExtraMetadata, ...asObject(metadata) }, originInput);
|
|
91
118
|
}
|
|
92
119
|
grouped.child = (moreMetadata) => bindGroup(boundGroup, originInput, { ...mergedExtraMetadata, ...asObject(moreMetadata) });
|
|
93
120
|
return grouped;
|
|
94
|
-
}
|
|
95
|
-
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createLoggerApi(args) {
|
|
124
|
+
return {
|
|
96
125
|
group(groupName) {
|
|
97
|
-
return bindGroup(groupName || defaultGroup);
|
|
126
|
+
return args.bindGroup(groupName || args.defaultGroup);
|
|
98
127
|
},
|
|
99
128
|
withScope(source, groupName, instance) {
|
|
100
|
-
|
|
101
|
-
source: toString(source) || defaultSource,
|
|
129
|
+
return args.bindGroup(groupName || args.defaultGroup, {
|
|
130
|
+
source: toString(source) || args.defaultSource,
|
|
102
131
|
instance: instance == null ? null : String(instance),
|
|
103
|
-
};
|
|
104
|
-
return bindGroup(groupName || defaultGroup, originInput);
|
|
132
|
+
});
|
|
105
133
|
},
|
|
106
134
|
setEnabled(flag) {
|
|
107
|
-
|
|
135
|
+
args.setEnabled(Boolean(flag));
|
|
108
136
|
},
|
|
109
137
|
logError(error, metadata, source) {
|
|
110
|
-
|
|
111
|
-
const groupName = toString(meta.group) || defaultGroup;
|
|
112
|
-
const originSource = toString(source) || defaultSource;
|
|
113
|
-
if (error instanceof Error) {
|
|
114
|
-
emit("error", groupName, error.message, { ...meta, stack: error.stack }, { source: originSource });
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
emit("error", groupName, String(error), meta, { source: originSource });
|
|
138
|
+
emitLogError(args.emit, error, metadata, source, args.defaultGroup, args.defaultSource);
|
|
118
139
|
},
|
|
119
140
|
flush() {
|
|
120
|
-
return options.flush();
|
|
141
|
+
return args.options.flush();
|
|
121
142
|
},
|
|
122
143
|
async close() {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
closed = true;
|
|
126
|
-
await options.close();
|
|
144
|
+
args.setClosed(true);
|
|
145
|
+
await args.options.close();
|
|
127
146
|
},
|
|
128
147
|
getStats() {
|
|
129
|
-
return options.getStats();
|
|
148
|
+
return args.options.getStats();
|
|
130
149
|
},
|
|
131
150
|
};
|
|
151
|
+
}
|
|
152
|
+
function emitLogError(emit, error, metadata, source, defaultGroup, defaultSource) {
|
|
153
|
+
const meta = asObject(metadata);
|
|
154
|
+
const groupName = toString(meta.group) || defaultGroup;
|
|
155
|
+
const originSource = toString(source) || defaultSource;
|
|
156
|
+
if (error instanceof Error) {
|
|
157
|
+
emit("error", groupName, error.message, { ...meta, stack: error.stack }, { source: originSource });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
emit("error", groupName, String(error), meta, { source: originSource });
|
|
161
|
+
}
|
|
162
|
+
function attachLevelLoggers(api, levels, defaultGroup, emit) {
|
|
132
163
|
for (const level of Object.keys(levels)) {
|
|
133
164
|
api[level] = function levelLogger() {
|
|
134
165
|
const parsed = parseCallArguments(arguments, defaultGroup);
|
|
135
166
|
emit(level, parsed.group, parsed.message, parsed.metadata);
|
|
136
167
|
};
|
|
137
168
|
}
|
|
169
|
+
}
|
|
170
|
+
function prepareEntry(args) {
|
|
171
|
+
const level = normalizeLevel(args.levelInput, args.levels);
|
|
172
|
+
const levelConfig = args.levels[level] || args.levels.info;
|
|
173
|
+
if (levelConfig.weight < args.threshold) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const rawMetadata = {
|
|
177
|
+
...args.defaultMetadata,
|
|
178
|
+
...asObject(args.metadataInput),
|
|
179
|
+
};
|
|
180
|
+
const recordedAt = toString(rawMetadata.__recorded_at) || new Date().toISOString();
|
|
181
|
+
const metadata = prepareMetadata(rawMetadata, args.options.serializers, args.options.redact);
|
|
182
|
+
const originSource = args.originInput?.source || args.defaultSource;
|
|
183
|
+
const originInstance = Object.prototype.hasOwnProperty.call(args.originInput || {}, "instance")
|
|
184
|
+
? args.originInput?.instance
|
|
185
|
+
: null;
|
|
186
|
+
const entry = {
|
|
187
|
+
recorded_at: recordedAt,
|
|
188
|
+
level,
|
|
189
|
+
group: normGroup(args.groupInput || args.defaultGroup).key,
|
|
190
|
+
message: typeof args.messageInput === "string" ? args.messageInput : String(args.messageInput ?? ""),
|
|
191
|
+
origin: buildOrigin(originSource, originInstance),
|
|
192
|
+
};
|
|
193
|
+
if (typeof args.options.getPartition === "function") {
|
|
194
|
+
entry.partition = args.options.getPartition() ?? null;
|
|
195
|
+
}
|
|
196
|
+
if (Object.keys(metadata).length) {
|
|
197
|
+
entry.metadata = metadata;
|
|
198
|
+
}
|
|
138
199
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
200
|
+
entry,
|
|
201
|
+
levelConfig,
|
|
141
202
|
};
|
|
142
203
|
}
|
|
143
204
|
export { DEFAULT_GROUP, buildOrigin, createCommonLogger, parseCallArguments, shouldKeepSample };
|