@spinajs/log 2.0.481 → 2.0.482
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/README.md +744 -0
- package/lib/cjs/archive/LogArchiveService.d.ts +75 -0
- package/lib/cjs/archive/LogArchiveService.d.ts.map +1 -0
- package/lib/cjs/archive/LogArchiveService.js +189 -0
- package/lib/cjs/archive/LogArchiveService.js.map +1 -0
- package/lib/cjs/archive/archive-strategy.d.ts +32 -0
- package/lib/cjs/archive/archive-strategy.d.ts.map +1 -0
- package/lib/cjs/archive/archive-strategy.js +43 -0
- package/lib/cjs/archive/archive-strategy.js.map +1 -0
- package/lib/cjs/archive/context.d.ts +50 -0
- package/lib/cjs/archive/context.d.ts.map +1 -0
- package/lib/cjs/archive/context.js +3 -0
- package/lib/cjs/archive/context.js.map +1 -0
- package/lib/cjs/archive/index.d.ts +10 -0
- package/lib/cjs/archive/index.d.ts.map +1 -0
- package/lib/cjs/archive/index.js +26 -0
- package/lib/cjs/archive/index.js.map +1 -0
- package/lib/cjs/archive/retention-strategy.d.ts +26 -0
- package/lib/cjs/archive/retention-strategy.d.ts.map +1 -0
- package/lib/cjs/archive/retention-strategy.js +42 -0
- package/lib/cjs/archive/retention-strategy.js.map +1 -0
- package/lib/cjs/archive/strategies/AgeLogRetentionStrategy.d.ts +10 -0
- package/lib/cjs/archive/strategies/AgeLogRetentionStrategy.d.ts.map +1 -0
- package/lib/cjs/archive/strategies/AgeLogRetentionStrategy.js +46 -0
- package/lib/cjs/archive/strategies/AgeLogRetentionStrategy.js.map +1 -0
- package/lib/cjs/archive/strategies/CountLogRetentionStrategy.d.ts +10 -0
- package/lib/cjs/archive/strategies/CountLogRetentionStrategy.d.ts.map +1 -0
- package/lib/cjs/archive/strategies/CountLogRetentionStrategy.js +42 -0
- package/lib/cjs/archive/strategies/CountLogRetentionStrategy.js.map +1 -0
- package/lib/cjs/archive/strategies/CronLogArchiveStrategy.d.ts +15 -0
- package/lib/cjs/archive/strategies/CronLogArchiveStrategy.d.ts.map +1 -0
- package/lib/cjs/archive/strategies/CronLogArchiveStrategy.js +52 -0
- package/lib/cjs/archive/strategies/CronLogArchiveStrategy.js.map +1 -0
- package/lib/cjs/archive/strategies/SizeLogArchiveStrategy.d.ts +18 -0
- package/lib/cjs/archive/strategies/SizeLogArchiveStrategy.d.ts.map +1 -0
- package/lib/cjs/archive/strategies/SizeLogArchiveStrategy.js +63 -0
- package/lib/cjs/archive/strategies/SizeLogArchiveStrategy.js.map +1 -0
- package/lib/cjs/archive/strategies/util.d.ts +28 -0
- package/lib/cjs/archive/strategies/util.d.ts.map +1 -0
- package/lib/cjs/archive/strategies/util.js +59 -0
- package/lib/cjs/archive/strategies/util.js.map +1 -0
- package/lib/cjs/bootstrap.d.ts.map +1 -1
- package/lib/cjs/bootstrap.js +24 -1
- package/lib/cjs/bootstrap.js.map +1 -1
- package/lib/cjs/callsite.d.ts +26 -0
- package/lib/cjs/callsite.d.ts.map +1 -0
- package/lib/cjs/callsite.js +60 -0
- package/lib/cjs/callsite.js.map +1 -0
- package/lib/cjs/config/log.d.ts +96 -0
- package/lib/cjs/config/log.d.ts.map +1 -0
- package/lib/cjs/config/log.js +75 -0
- package/lib/cjs/config/log.js.map +1 -0
- package/lib/cjs/context.browser.d.ts +46 -0
- package/lib/cjs/context.browser.d.ts.map +1 -0
- package/lib/cjs/context.browser.js +85 -0
- package/lib/cjs/context.browser.js.map +1 -0
- package/lib/cjs/context.d.ts +61 -0
- package/lib/cjs/context.d.ts.map +1 -0
- package/lib/cjs/context.js +92 -0
- package/lib/cjs/context.js.map +1 -0
- package/lib/cjs/filters/LevelFilter.d.ts +24 -0
- package/lib/cjs/filters/LevelFilter.d.ts.map +1 -0
- package/lib/cjs/filters/LevelFilter.js +39 -0
- package/lib/cjs/filters/LevelFilter.js.map +1 -0
- package/lib/cjs/filters/MatchFilter.d.ts +30 -0
- package/lib/cjs/filters/MatchFilter.d.ts.map +1 -0
- package/lib/cjs/filters/MatchFilter.js +65 -0
- package/lib/cjs/filters/MatchFilter.js.map +1 -0
- package/lib/cjs/filters/RateLimitFilter.d.ts +37 -0
- package/lib/cjs/filters/RateLimitFilter.d.ts.map +1 -0
- package/lib/cjs/filters/RateLimitFilter.js +70 -0
- package/lib/cjs/filters/RateLimitFilter.js.map +1 -0
- package/lib/cjs/filters/index.d.ts +4 -0
- package/lib/cjs/filters/index.d.ts.map +1 -0
- package/lib/cjs/filters/index.js +20 -0
- package/lib/cjs/filters/index.js.map +1 -0
- package/lib/cjs/index.browser.d.ts +14 -0
- package/lib/cjs/index.browser.d.ts.map +1 -0
- package/lib/cjs/index.browser.js +46 -0
- package/lib/cjs/index.browser.js.map +1 -0
- package/lib/cjs/index.d.ts +8 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/log.d.ts +60 -1
- package/lib/cjs/log.d.ts.map +1 -1
- package/lib/cjs/log.js +294 -32
- package/lib/cjs/log.js.map +1 -1
- package/lib/cjs/perf/LogMetricSink.d.ts +28 -0
- package/lib/cjs/perf/LogMetricSink.d.ts.map +1 -0
- package/lib/cjs/perf/LogMetricSink.js +120 -0
- package/lib/cjs/perf/LogMetricSink.js.map +1 -0
- package/lib/cjs/perf/measure.d.ts +9 -0
- package/lib/cjs/perf/measure.d.ts.map +1 -0
- package/lib/cjs/perf/measure.js +21 -0
- package/lib/cjs/perf/measure.js.map +1 -0
- package/lib/cjs/perf.d.ts +9 -0
- package/lib/cjs/perf.d.ts.map +1 -0
- package/lib/cjs/perf.js +18 -0
- package/lib/cjs/perf.js.map +1 -0
- package/lib/cjs/schemas/log.configuration.d.ts +151 -18
- package/lib/cjs/schemas/log.configuration.d.ts.map +1 -1
- package/lib/cjs/schemas/log.configuration.js +154 -21
- package/lib/cjs/schemas/log.configuration.js.map +1 -1
- package/lib/cjs/targets/BrowserConsoleTarget.d.ts +48 -0
- package/lib/cjs/targets/BrowserConsoleTarget.d.ts.map +1 -0
- package/lib/cjs/targets/BrowserConsoleTarget.js +48 -0
- package/lib/cjs/targets/BrowserConsoleTarget.js.map +1 -0
- package/lib/cjs/targets/ColoredConsoleTarget.d.ts.map +1 -1
- package/lib/cjs/targets/ColoredConsoleTarget.js +21 -12
- package/lib/cjs/targets/ColoredConsoleTarget.js.map +1 -1
- package/lib/cjs/targets/FileTarget.d.ts +96 -20
- package/lib/cjs/targets/FileTarget.d.ts.map +1 -1
- package/lib/cjs/targets/FileTarget.js +188 -225
- package/lib/cjs/targets/FileTarget.js.map +1 -1
- package/lib/cjs/targets/JsonFileTarget.d.ts +19 -0
- package/lib/cjs/targets/JsonFileTarget.d.ts.map +1 -0
- package/lib/cjs/targets/JsonFileTarget.js +44 -0
- package/lib/cjs/targets/JsonFileTarget.js.map +1 -0
- package/lib/cjs/targets/JsonTarget.d.ts +27 -0
- package/lib/cjs/targets/JsonTarget.d.ts.map +1 -0
- package/lib/cjs/targets/JsonTarget.js +46 -0
- package/lib/cjs/targets/JsonTarget.js.map +1 -0
- package/lib/cjs/targets/MemoryTarget.d.ts +33 -0
- package/lib/cjs/targets/MemoryTarget.d.ts.map +1 -0
- package/lib/cjs/targets/MemoryTarget.js +63 -0
- package/lib/cjs/targets/MemoryTarget.js.map +1 -0
- package/lib/cjs/targets/index.d.ts +7 -0
- package/lib/cjs/targets/index.d.ts.map +1 -1
- package/lib/cjs/targets/index.js +7 -0
- package/lib/cjs/targets/index.js.map +1 -1
- package/lib/cjs/targets/wrappers/AutoFlushTarget.d.ts +37 -0
- package/lib/cjs/targets/wrappers/AutoFlushTarget.d.ts.map +1 -0
- package/lib/cjs/targets/wrappers/AutoFlushTarget.js +48 -0
- package/lib/cjs/targets/wrappers/AutoFlushTarget.js.map +1 -0
- package/lib/cjs/targets/wrappers/FallbackGroupTarget.d.ts +45 -0
- package/lib/cjs/targets/wrappers/FallbackGroupTarget.d.ts.map +1 -0
- package/lib/cjs/targets/wrappers/FallbackGroupTarget.js +94 -0
- package/lib/cjs/targets/wrappers/FallbackGroupTarget.js.map +1 -0
- package/lib/cjs/targets/wrappers/RetryingTarget.d.ts +44 -0
- package/lib/cjs/targets/wrappers/RetryingTarget.d.ts.map +1 -0
- package/lib/cjs/targets/wrappers/RetryingTarget.js +61 -0
- package/lib/cjs/targets/wrappers/RetryingTarget.js.map +1 -0
- package/lib/cjs/targets/wrappers/SplitGroupTarget.d.ts +30 -0
- package/lib/cjs/targets/wrappers/SplitGroupTarget.d.ts.map +1 -0
- package/lib/cjs/targets/wrappers/SplitGroupTarget.js +52 -0
- package/lib/cjs/targets/wrappers/SplitGroupTarget.js.map +1 -0
- package/lib/cjs/traceparent.d.ts +63 -0
- package/lib/cjs/traceparent.d.ts.map +1 -0
- package/lib/cjs/traceparent.js +107 -0
- package/lib/cjs/traceparent.js.map +1 -0
- package/lib/mjs/archive/LogArchiveService.d.ts +75 -0
- package/lib/mjs/archive/LogArchiveService.d.ts.map +1 -0
- package/lib/mjs/archive/LogArchiveService.js +186 -0
- package/lib/mjs/archive/LogArchiveService.js.map +1 -0
- package/lib/mjs/archive/archive-strategy.d.ts +32 -0
- package/lib/mjs/archive/archive-strategy.d.ts.map +1 -0
- package/lib/mjs/archive/archive-strategy.js +39 -0
- package/lib/mjs/archive/archive-strategy.js.map +1 -0
- package/lib/mjs/archive/context.d.ts +50 -0
- package/lib/mjs/archive/context.d.ts.map +1 -0
- package/lib/mjs/archive/context.js +2 -0
- package/lib/mjs/archive/context.js.map +1 -0
- package/lib/mjs/archive/index.d.ts +10 -0
- package/lib/mjs/archive/index.d.ts.map +1 -0
- package/lib/mjs/archive/index.js +10 -0
- package/lib/mjs/archive/index.js.map +1 -0
- package/lib/mjs/archive/retention-strategy.d.ts +26 -0
- package/lib/mjs/archive/retention-strategy.d.ts.map +1 -0
- package/lib/mjs/archive/retention-strategy.js +38 -0
- package/lib/mjs/archive/retention-strategy.js.map +1 -0
- package/lib/mjs/archive/strategies/AgeLogRetentionStrategy.d.ts +10 -0
- package/lib/mjs/archive/strategies/AgeLogRetentionStrategy.d.ts.map +1 -0
- package/lib/mjs/archive/strategies/AgeLogRetentionStrategy.js +43 -0
- package/lib/mjs/archive/strategies/AgeLogRetentionStrategy.js.map +1 -0
- package/lib/mjs/archive/strategies/CountLogRetentionStrategy.d.ts +10 -0
- package/lib/mjs/archive/strategies/CountLogRetentionStrategy.d.ts.map +1 -0
- package/lib/mjs/archive/strategies/CountLogRetentionStrategy.js +39 -0
- package/lib/mjs/archive/strategies/CountLogRetentionStrategy.js.map +1 -0
- package/lib/mjs/archive/strategies/CronLogArchiveStrategy.d.ts +15 -0
- package/lib/mjs/archive/strategies/CronLogArchiveStrategy.d.ts.map +1 -0
- package/lib/mjs/archive/strategies/CronLogArchiveStrategy.js +49 -0
- package/lib/mjs/archive/strategies/CronLogArchiveStrategy.js.map +1 -0
- package/lib/mjs/archive/strategies/SizeLogArchiveStrategy.d.ts +18 -0
- package/lib/mjs/archive/strategies/SizeLogArchiveStrategy.d.ts.map +1 -0
- package/lib/mjs/archive/strategies/SizeLogArchiveStrategy.js +60 -0
- package/lib/mjs/archive/strategies/SizeLogArchiveStrategy.js.map +1 -0
- package/lib/mjs/archive/strategies/util.d.ts +28 -0
- package/lib/mjs/archive/strategies/util.d.ts.map +1 -0
- package/lib/mjs/archive/strategies/util.js +54 -0
- package/lib/mjs/archive/strategies/util.js.map +1 -0
- package/lib/mjs/bootstrap.d.ts.map +1 -1
- package/lib/mjs/bootstrap.js +25 -2
- package/lib/mjs/bootstrap.js.map +1 -1
- package/lib/mjs/callsite.d.ts +26 -0
- package/lib/mjs/callsite.d.ts.map +1 -0
- package/lib/mjs/callsite.js +57 -0
- package/lib/mjs/callsite.js.map +1 -0
- package/lib/mjs/config/log.d.ts +96 -0
- package/lib/mjs/config/log.d.ts.map +1 -0
- package/lib/mjs/config/log.js +72 -0
- package/lib/mjs/config/log.js.map +1 -0
- package/lib/mjs/context.browser.d.ts +46 -0
- package/lib/mjs/context.browser.d.ts.map +1 -0
- package/lib/mjs/context.browser.js +81 -0
- package/lib/mjs/context.browser.js.map +1 -0
- package/lib/mjs/context.d.ts +61 -0
- package/lib/mjs/context.d.ts.map +1 -0
- package/lib/mjs/context.js +88 -0
- package/lib/mjs/context.js.map +1 -0
- package/lib/mjs/filters/LevelFilter.d.ts +24 -0
- package/lib/mjs/filters/LevelFilter.d.ts.map +1 -0
- package/lib/mjs/filters/LevelFilter.js +36 -0
- package/lib/mjs/filters/LevelFilter.js.map +1 -0
- package/lib/mjs/filters/MatchFilter.d.ts +30 -0
- package/lib/mjs/filters/MatchFilter.d.ts.map +1 -0
- package/lib/mjs/filters/MatchFilter.js +62 -0
- package/lib/mjs/filters/MatchFilter.js.map +1 -0
- package/lib/mjs/filters/RateLimitFilter.d.ts +37 -0
- package/lib/mjs/filters/RateLimitFilter.d.ts.map +1 -0
- package/lib/mjs/filters/RateLimitFilter.js +67 -0
- package/lib/mjs/filters/RateLimitFilter.js.map +1 -0
- package/lib/mjs/filters/index.d.ts +4 -0
- package/lib/mjs/filters/index.d.ts.map +1 -0
- package/lib/mjs/filters/index.js +4 -0
- package/lib/mjs/filters/index.js.map +1 -0
- package/lib/mjs/index.browser.d.ts +14 -0
- package/lib/mjs/index.browser.d.ts.map +1 -0
- package/lib/mjs/index.browser.js +30 -0
- package/lib/mjs/index.browser.js.map +1 -0
- package/lib/mjs/index.d.ts +8 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +8 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/log.d.ts +60 -1
- package/lib/mjs/log.d.ts.map +1 -1
- package/lib/mjs/log.js +295 -33
- package/lib/mjs/log.js.map +1 -1
- package/lib/mjs/perf/LogMetricSink.d.ts +28 -0
- package/lib/mjs/perf/LogMetricSink.d.ts.map +1 -0
- package/lib/mjs/perf/LogMetricSink.js +117 -0
- package/lib/mjs/perf/LogMetricSink.js.map +1 -0
- package/lib/mjs/perf/measure.d.ts +9 -0
- package/lib/mjs/perf/measure.d.ts.map +1 -0
- package/lib/mjs/perf/measure.js +18 -0
- package/lib/mjs/perf/measure.js.map +1 -0
- package/lib/mjs/perf.d.ts +9 -0
- package/lib/mjs/perf.d.ts.map +1 -0
- package/lib/mjs/perf.js +15 -0
- package/lib/mjs/perf.js.map +1 -0
- package/lib/mjs/schemas/log.configuration.d.ts +151 -18
- package/lib/mjs/schemas/log.configuration.d.ts.map +1 -1
- package/lib/mjs/schemas/log.configuration.js +154 -21
- package/lib/mjs/schemas/log.configuration.js.map +1 -1
- package/lib/mjs/targets/BrowserConsoleTarget.d.ts +48 -0
- package/lib/mjs/targets/BrowserConsoleTarget.d.ts.map +1 -0
- package/lib/mjs/targets/BrowserConsoleTarget.js +45 -0
- package/lib/mjs/targets/BrowserConsoleTarget.js.map +1 -0
- package/lib/mjs/targets/ColoredConsoleTarget.d.ts.map +1 -1
- package/lib/mjs/targets/ColoredConsoleTarget.js +21 -9
- package/lib/mjs/targets/ColoredConsoleTarget.js.map +1 -1
- package/lib/mjs/targets/FileTarget.d.ts +96 -20
- package/lib/mjs/targets/FileTarget.d.ts.map +1 -1
- package/lib/mjs/targets/FileTarget.js +191 -192
- package/lib/mjs/targets/FileTarget.js.map +1 -1
- package/lib/mjs/targets/JsonFileTarget.d.ts +19 -0
- package/lib/mjs/targets/JsonFileTarget.d.ts.map +1 -0
- package/lib/mjs/targets/JsonFileTarget.js +41 -0
- package/lib/mjs/targets/JsonFileTarget.js.map +1 -0
- package/lib/mjs/targets/JsonTarget.d.ts +27 -0
- package/lib/mjs/targets/JsonTarget.d.ts.map +1 -0
- package/lib/mjs/targets/JsonTarget.js +43 -0
- package/lib/mjs/targets/JsonTarget.js.map +1 -0
- package/lib/mjs/targets/MemoryTarget.d.ts +33 -0
- package/lib/mjs/targets/MemoryTarget.d.ts.map +1 -0
- package/lib/mjs/targets/MemoryTarget.js +60 -0
- package/lib/mjs/targets/MemoryTarget.js.map +1 -0
- package/lib/mjs/targets/index.d.ts +7 -0
- package/lib/mjs/targets/index.d.ts.map +1 -1
- package/lib/mjs/targets/index.js +7 -0
- package/lib/mjs/targets/index.js.map +1 -1
- package/lib/mjs/targets/wrappers/AutoFlushTarget.d.ts +37 -0
- package/lib/mjs/targets/wrappers/AutoFlushTarget.d.ts.map +1 -0
- package/lib/mjs/targets/wrappers/AutoFlushTarget.js +45 -0
- package/lib/mjs/targets/wrappers/AutoFlushTarget.js.map +1 -0
- package/lib/mjs/targets/wrappers/FallbackGroupTarget.d.ts +45 -0
- package/lib/mjs/targets/wrappers/FallbackGroupTarget.d.ts.map +1 -0
- package/lib/mjs/targets/wrappers/FallbackGroupTarget.js +91 -0
- package/lib/mjs/targets/wrappers/FallbackGroupTarget.js.map +1 -0
- package/lib/mjs/targets/wrappers/RetryingTarget.d.ts +44 -0
- package/lib/mjs/targets/wrappers/RetryingTarget.d.ts.map +1 -0
- package/lib/mjs/targets/wrappers/RetryingTarget.js +58 -0
- package/lib/mjs/targets/wrappers/RetryingTarget.js.map +1 -0
- package/lib/mjs/targets/wrappers/SplitGroupTarget.d.ts +30 -0
- package/lib/mjs/targets/wrappers/SplitGroupTarget.d.ts.map +1 -0
- package/lib/mjs/targets/wrappers/SplitGroupTarget.js +49 -0
- package/lib/mjs/targets/wrappers/SplitGroupTarget.js.map +1 -0
- package/lib/mjs/traceparent.d.ts +63 -0
- package/lib/mjs/traceparent.d.ts.map +1 -0
- package/lib/mjs/traceparent.js +100 -0
- package/lib/mjs/traceparent.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +25 -15
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { posix } from "path";
|
|
2
|
+
/**
|
|
3
|
+
* Prefix every archived file name gets. Only files under `archiveDir` starting
|
|
4
|
+
* with this prefix are considered archives ( so the active log dir, when it is
|
|
5
|
+
* the same directory as the archive dir, is not touched ).
|
|
6
|
+
*/
|
|
7
|
+
export const ARCHIVE_PREFIX = "archived_";
|
|
8
|
+
/**
|
|
9
|
+
* Joins archive dir + file name with forward slashes. fs providers resolve
|
|
10
|
+
* paths against their base path and normalize separators, so a posix join keeps
|
|
11
|
+
* behaviour identical across platforms.
|
|
12
|
+
*/
|
|
13
|
+
export function archivePath(ctx, name) {
|
|
14
|
+
return ctx.archiveDir ? posix.join(ctx.archiveDir, name) : name;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lists archive files in `ctx.archiveDir` on `ctx.archiveFs`, sorted ascending
|
|
18
|
+
* by modification time ( oldest first, newest last ). Only files carrying the
|
|
19
|
+
* archive prefix are returned; directories and unrelated files are ignored.
|
|
20
|
+
*/
|
|
21
|
+
export async function listArchives(ctx) {
|
|
22
|
+
let names;
|
|
23
|
+
try {
|
|
24
|
+
names = await ctx.archiveFs.list(ctx.archiveDir || "/");
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// archive dir may not exist yet ( nothing rotated )
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const entries = [];
|
|
31
|
+
for (const name of names) {
|
|
32
|
+
if (!name.startsWith(ARCHIVE_PREFIX)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const p = archivePath(ctx, name);
|
|
36
|
+
try {
|
|
37
|
+
const stat = await ctx.archiveFs.stat(p);
|
|
38
|
+
if (stat.IsDirectory) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
entries.push({ path: p, stat });
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// stat can fail on a file removed concurrently - skip it
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
entries.sort((a, b) => {
|
|
48
|
+
const at = a.stat.ModifiedTime?.toMillis() ?? 0;
|
|
49
|
+
const bt = b.stat.ModifiedTime?.toMillis() ?? 0;
|
|
50
|
+
return at - bt;
|
|
51
|
+
});
|
|
52
|
+
return entries;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/archive/strategies/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAG7B;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAU1C;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAuB,EAAE,IAAY;IAC/D,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAuB;IACxD,IAAI,KAAe,CAAC;IACpB,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;QACpD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YACrC,SAAS;QACX,CAAC;QAED,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACzC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACrB,SAAS;YACX,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,yDAAyD;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACpB,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChD,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChD,OAAO,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,YAAY,EAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,YAAY,EAAM,MAAM,aAAa,CAAC;AAkC3D,qBACa,cAAe,SAAQ,YAAY;IACvC,SAAS,IAAI,IAAI;CAmCzB"}
|
package/lib/mjs/bootstrap.js
CHANGED
|
@@ -6,7 +6,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Configuration } from "@spinajs/configuration";
|
|
8
8
|
import { Injectable, Bootstrapper, DI } from "@spinajs/di";
|
|
9
|
-
import { Log } from "@spinajs/log-common";
|
|
9
|
+
import { Log, setLogContextProvider } from "@spinajs/log-common";
|
|
10
|
+
import { LogContext, scalarContext } from "./context.js";
|
|
11
|
+
import { wirePerfScope } from "./perf.js";
|
|
10
12
|
import CONFIGURATION_SCHEMA from "./schemas/log.configuration.js";
|
|
11
13
|
const uncaughtExceptionHandler = (err) => {
|
|
12
14
|
// if we have configuration resolved, we can assume that logger can read configuration
|
|
@@ -32,15 +34,36 @@ const unhandledRejection = (reason, p) => {
|
|
|
32
34
|
console.error("Unhandled rejection: \n reason: " + reason.message + " \n stack:" + reason.stack);
|
|
33
35
|
}
|
|
34
36
|
};
|
|
37
|
+
// Guard so a double bootstrap ( eg. re-run in the same process ) does not
|
|
38
|
+
// register the beforeExit drain twice.
|
|
39
|
+
let beforeExitAttached = false;
|
|
35
40
|
let LogBotstrapper = class LogBotstrapper extends Bootstrapper {
|
|
36
41
|
bootstrap() {
|
|
37
42
|
DI.register(CONFIGURATION_SCHEMA).asValue("__configurationSchema__");
|
|
43
|
+
// Best-effort teardown drain: on a CLEAN process exit, force-flush every
|
|
44
|
+
// logger's targets so buffered File / Loki / OTLP entries are written out.
|
|
45
|
+
// beforeExit does NOT run on hard exits ( process.exit / signals / crashes ),
|
|
46
|
+
// so this only catches clean drains. Node-only ( guard mirrors
|
|
47
|
+
// internal-logger ); do not double-register.
|
|
48
|
+
if (!beforeExitAttached && typeof process !== "undefined" && typeof process.on === "function") {
|
|
49
|
+
beforeExitAttached = true;
|
|
50
|
+
process.on("beforeExit", () => {
|
|
51
|
+
void Log.flushAll();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
// Feed the ambient async-context store into every log entry ( merged at
|
|
55
|
+
// lowest precedence by createLogMessageObject ). LogContext resolves the
|
|
56
|
+
// same DI-singleton AsyncLocalStorage the http module runs per action, so
|
|
57
|
+
// logs inherit requestId / realIp / ... for free.
|
|
58
|
+
setLogContextProvider(() => scalarContext(LogContext.active()));
|
|
59
|
+
// Wire the per-request perf accumulator onto the same async store.
|
|
60
|
+
wirePerfScope();
|
|
38
61
|
// check if we run tests,
|
|
39
62
|
// hook for uncaughtException causes to not showing
|
|
40
63
|
// mocha errors in console
|
|
41
64
|
if (!process.env.TESTING) {
|
|
42
65
|
process.removeListener("uncaughtException", uncaughtExceptionHandler);
|
|
43
|
-
process.removeListener("unhandledRejection",
|
|
66
|
+
process.removeListener("unhandledRejection", unhandledRejection);
|
|
44
67
|
process.on("uncaughtException", uncaughtExceptionHandler);
|
|
45
68
|
process.on("unhandledRejection", unhandledRejection);
|
|
46
69
|
}
|
package/lib/mjs/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,oBAAoB,MAAM,gCAAgC,CAAC;AAElE,MAAM,wBAAwB,GAAG,CAAC,GAAU,EAAE,EAAE;IAC9C,sFAAsF;IACtF,wBAAwB;IACxB,wBAAwB;IACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACzC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,kCAAkC,GAAG,GAAG,CAAC,OAAO,GAAG,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAa,EAAE,CAAmB,EAAE,EAAE;IAChE,sFAAsF;IACtF,wBAAwB;IACxB,wBAAwB;IACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACzC,GAAG,CAAC,KAAK,CAAC,MAAe,EAAE,mCAAmC,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,kCAAkC,GAAG,MAAM,CAAC,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACnG,CAAC;AACH,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,oBAAoB,MAAM,gCAAgC,CAAC;AAElE,MAAM,wBAAwB,GAAG,CAAC,GAAU,EAAE,EAAE;IAC9C,sFAAsF;IACtF,wBAAwB;IACxB,wBAAwB;IACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACzC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,kCAAkC,GAAG,GAAG,CAAC,OAAO,GAAG,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,MAAa,EAAE,CAAmB,EAAE,EAAE;IAChE,sFAAsF;IACtF,wBAAwB;IACxB,wBAAwB;IACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACzC,GAAG,CAAC,KAAK,CAAC,MAAe,EAAE,mCAAmC,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,kCAAkC,GAAG,MAAM,CAAC,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACnG,CAAC;AACH,CAAC,CAAC;AAEF,0EAA0E;AAC1E,uCAAuC;AACvC,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAGxB,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,YAAY;IACvC,SAAS;QACd,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAErE,yEAAyE;QACzE,2EAA2E;QAC3E,8EAA8E;QAC9E,+DAA+D;QAC/D,6CAA6C;QAC7C,IAAI,CAAC,kBAAkB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;YAC9F,kBAAkB,GAAG,IAAI,CAAC;YAC1B,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;gBAC5B,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC;QAED,wEAAwE;QACxE,yEAAyE;QACzE,0EAA0E;QAC1E,kDAAkD;QAClD,qBAAqB,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAEhE,mEAAmE;QACnE,aAAa,EAAE,CAAC;QAEhB,yBAAyB;QACzB,mDAAmD;QACnD,0BAA0B;QAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,wBAAwB,CAAC,CAAC;YACtE,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;YAEjE,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,wBAAwB,CAAC,CAAC;YAC1D,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF,CAAA;AApCY,cAAc;IAD1B,UAAU,CAAC,YAAY,CAAC;GACZ,cAAc,CAoC1B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort caller-frame capture for the `${callsite}` layout variable.
|
|
3
|
+
*
|
|
4
|
+
* NLog gates stack-trace capture behind `StackTraceUsage` so that logging is
|
|
5
|
+
* zero-cost unless a target's layout actually references the caller. This
|
|
6
|
+
* mirrors that: {@link FrameworkLogger} only calls {@link captureCallsite}
|
|
7
|
+
* when some target's layout references `${callsite}`, so the `new Error()`
|
|
8
|
+
* ( the only cost here ) is never constructed otherwise.
|
|
9
|
+
*
|
|
10
|
+
* The parser is intentionally defensive - it must NEVER throw. Browser stack
|
|
11
|
+
* formats vary and V8's format is not guaranteed, so an unparseable stack just
|
|
12
|
+
* yields `""` rather than crashing a log call.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Walk the current stack and return the first frame OUTSIDE the log package -
|
|
16
|
+
* i.e. the user's call site - as `"basename:line"` ( e.g. `service.ts:42` ).
|
|
17
|
+
*
|
|
18
|
+
* Internal frames belonging to the logger itself ( `log.ts`, `callsite.ts`,
|
|
19
|
+
* the `log-common` package, `wrapWrite`, `createLogMessageObject` ) are skipped
|
|
20
|
+
* so the returned frame is the caller of `log.info(...)` / `log.error(...)`.
|
|
21
|
+
*
|
|
22
|
+
* Returns `""` when no frame can be parsed ( no stack, or an unrecognized
|
|
23
|
+
* stack format ). Best-effort by design.
|
|
24
|
+
*/
|
|
25
|
+
export declare function captureCallsite(): string;
|
|
26
|
+
//# sourceMappingURL=callsite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callsite.d.ts","sourceRoot":"","sources":["../../src/callsite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAmCxC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort caller-frame capture for the `${callsite}` layout variable.
|
|
3
|
+
*
|
|
4
|
+
* NLog gates stack-trace capture behind `StackTraceUsage` so that logging is
|
|
5
|
+
* zero-cost unless a target's layout actually references the caller. This
|
|
6
|
+
* mirrors that: {@link FrameworkLogger} only calls {@link captureCallsite}
|
|
7
|
+
* when some target's layout references `${callsite}`, so the `new Error()`
|
|
8
|
+
* ( the only cost here ) is never constructed otherwise.
|
|
9
|
+
*
|
|
10
|
+
* The parser is intentionally defensive - it must NEVER throw. Browser stack
|
|
11
|
+
* formats vary and V8's format is not guaranteed, so an unparseable stack just
|
|
12
|
+
* yields `""` rather than crashing a log call.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Walk the current stack and return the first frame OUTSIDE the log package -
|
|
16
|
+
* i.e. the user's call site - as `"basename:line"` ( e.g. `service.ts:42` ).
|
|
17
|
+
*
|
|
18
|
+
* Internal frames belonging to the logger itself ( `log.ts`, `callsite.ts`,
|
|
19
|
+
* the `log-common` package, `wrapWrite`, `createLogMessageObject` ) are skipped
|
|
20
|
+
* so the returned frame is the caller of `log.info(...)` / `log.error(...)`.
|
|
21
|
+
*
|
|
22
|
+
* Returns `""` when no frame can be parsed ( no stack, or an unrecognized
|
|
23
|
+
* stack format ). Best-effort by design.
|
|
24
|
+
*/
|
|
25
|
+
export function captureCallsite() {
|
|
26
|
+
const stack = new Error().stack;
|
|
27
|
+
if (!stack) {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
const lines = stack.split("\n");
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
// only real stack frames ( " at ..." ) - skip the leading "Error" line
|
|
33
|
+
// and any non-frame text.
|
|
34
|
+
if (!/\bat\b/.test(line)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// skip frames that live inside the logger's own code:
|
|
38
|
+
// - files log.ts / callsite.ts ( source ) or log.js / callsite.js ( built )
|
|
39
|
+
// - anything under a `log` or `log-common` package's src/ or lib/ tree
|
|
40
|
+
// - the internal helpers wrapWrite / createLogMessageObject
|
|
41
|
+
if (/[\\/]log(-common)?[\\/](src|lib)[\\/]|[\\/](log|callsite)\.(ts|js|mjs|cjs)\b|\bwrapWrite\b|\bcreateLogMessageObject\b|\bcaptureCallsite\b/.test(line)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
// extract "path:line" from either:
|
|
45
|
+
// " at fn (path:line:col)" ( named frame )
|
|
46
|
+
// " at path:line:col" ( anonymous frame )
|
|
47
|
+
const m = line.match(/\(?([^()]+):(\d+):(\d+)\)?\s*$/);
|
|
48
|
+
if (m) {
|
|
49
|
+
// basename only - keeps rendered log lines short and stable across
|
|
50
|
+
// machines ( full absolute paths differ per checkout ).
|
|
51
|
+
const file = m[1].split(/[\\/]/).pop() ?? m[1];
|
|
52
|
+
return `${file}:${m[2]}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=callsite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callsite.js","sourceRoot":"","sources":["../../src/callsite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,0EAA0E;QAC1E,0BAA0B;QAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,SAAS;QACX,CAAC;QAED,sDAAsD;QACtD,6EAA6E;QAC7E,wEAAwE;QACxE,6DAA6D;QAC7D,IAAI,2IAA2I,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3J,SAAS;QACX,CAAC;QAED,mCAAmC;QACnC,kDAAkD;QAClD,sDAAsD;QACtD,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvD,IAAI,CAAC,EAAE,CAAC;YACN,mEAAmE;YACnE,wDAAwD;YACxD,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/C,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration shipped with @spinajs/log ( Node only ).
|
|
3
|
+
*
|
|
4
|
+
* Everything the log package can be tuned with lives here, so the configuration
|
|
5
|
+
* module surfaces a single, discoverable list of what can be changed:
|
|
6
|
+
*
|
|
7
|
+
* 1. a DEFAULT fs provider `fs-log-default` rooted at the working process
|
|
8
|
+
* directory, so FileTarget works without any user fs configuration,
|
|
9
|
+
* 2. `logger.file` - the default FileTarget options ( buffer / rotation /
|
|
10
|
+
* retention tunables ). FileTarget merges these UNDER any per-target
|
|
11
|
+
* `options`, and a user project config ( loaded last ) overrides them - the
|
|
12
|
+
* same override chain every other spinajs package uses.
|
|
13
|
+
*
|
|
14
|
+
* Config files are merged with array concatenation, so the provider entry is
|
|
15
|
+
* APPENDED to any providers the user configures.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Canonical default FileTarget options. This is the SINGLE source of truth for
|
|
19
|
+
* every log tunable - change a default HERE, never inline in the target or a
|
|
20
|
+
* strategy. It is exported ( not just embedded in the config below ) so the
|
|
21
|
+
* FileTarget can fall back to the exact same values when the config file is not
|
|
22
|
+
* discovered ( eg. isolated unit tests ), and so tests share one definition.
|
|
23
|
+
*/
|
|
24
|
+
export declare const LOG_FILE_DEFAULTS: {
|
|
25
|
+
/** fs provider holding the active log file. */
|
|
26
|
+
fs: string;
|
|
27
|
+
/** Zip the archived file when it is moved to the archive. */
|
|
28
|
+
compress: boolean;
|
|
29
|
+
/** Rotate the active log once it grows past this many bytes ( 1 MB ). */
|
|
30
|
+
maxSize: number;
|
|
31
|
+
/** Flush the in-memory buffer after this many messages. */
|
|
32
|
+
maxBufferSize: number;
|
|
33
|
+
/** Hard cap on buffered messages; oldest are dropped past this so a down sink cannot OOM. */
|
|
34
|
+
maxQueueSize: number;
|
|
35
|
+
/** Periodic flush tick in milliseconds, so a partial buffer is not held. */
|
|
36
|
+
flushInterval: number;
|
|
37
|
+
/** How often ( seconds ) SizeLogArchiveStrategy checks the active log size. */
|
|
38
|
+
archiveInterval: number;
|
|
39
|
+
/** Rotation trigger strategy ( decides WHEN to archive ). */
|
|
40
|
+
archiveStrategy: string;
|
|
41
|
+
/** Retention strategies applied in order after each rotation. */
|
|
42
|
+
retentionStrategies: string[];
|
|
43
|
+
/** Archives to keep ( CountLogRetentionStrategy ), oldest deleted first. */
|
|
44
|
+
maxArchiveFiles: number;
|
|
45
|
+
/** Max archive age in seconds ( AgeLogRetentionStrategy ), 7 days. */
|
|
46
|
+
maxAge: number;
|
|
47
|
+
};
|
|
48
|
+
declare const log: {
|
|
49
|
+
fs: {
|
|
50
|
+
defaultProvider: string;
|
|
51
|
+
providers: {
|
|
52
|
+
name: string;
|
|
53
|
+
service: string;
|
|
54
|
+
basePath: string;
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
57
|
+
logger: {
|
|
58
|
+
file: {
|
|
59
|
+
/** fs provider holding the active log file. */
|
|
60
|
+
fs: string;
|
|
61
|
+
/** Zip the archived file when it is moved to the archive. */
|
|
62
|
+
compress: boolean;
|
|
63
|
+
/** Rotate the active log once it grows past this many bytes ( 1 MB ). */
|
|
64
|
+
maxSize: number;
|
|
65
|
+
/** Flush the in-memory buffer after this many messages. */
|
|
66
|
+
maxBufferSize: number;
|
|
67
|
+
/** Hard cap on buffered messages; oldest are dropped past this so a down sink cannot OOM. */
|
|
68
|
+
maxQueueSize: number;
|
|
69
|
+
/** Periodic flush tick in milliseconds, so a partial buffer is not held. */
|
|
70
|
+
flushInterval: number;
|
|
71
|
+
/** How often ( seconds ) SizeLogArchiveStrategy checks the active log size. */
|
|
72
|
+
archiveInterval: number;
|
|
73
|
+
/** Rotation trigger strategy ( decides WHEN to archive ). */
|
|
74
|
+
archiveStrategy: string;
|
|
75
|
+
/** Retention strategies applied in order after each rotation. */
|
|
76
|
+
retentionStrategies: string[];
|
|
77
|
+
/** Archives to keep ( CountLogRetentionStrategy ), oldest deleted first. */
|
|
78
|
+
maxArchiveFiles: number;
|
|
79
|
+
/** Max archive age in seconds ( AgeLogRetentionStrategy ), 7 days. */
|
|
80
|
+
maxAge: number;
|
|
81
|
+
};
|
|
82
|
+
perf: {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
thresholds: {
|
|
85
|
+
"orm.query": number;
|
|
86
|
+
"http.request": number;
|
|
87
|
+
default: number;
|
|
88
|
+
};
|
|
89
|
+
overThresholdLevel: string;
|
|
90
|
+
underThresholdLevel: string;
|
|
91
|
+
logCounters: boolean;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export default log;
|
|
96
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/config/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;IAC5B,+CAA+C;;IAG/C,6DAA6D;;IAG7D,yEAAyE;;IAGzE,2DAA2D;;IAG3D,6FAA6F;;IAG7F,4EAA4E;;IAG5E,+EAA+E;;IAG/E,6DAA6D;;IAG7D,iEAAiE;;IAGjE,4EAA4E;;IAG5E,sEAAsE;;CAEvE,CAAC;AAEF,QAAA,MAAM,GAAG;;;;;;;;;;;YAlCP,+CAA+C;;YAG/C,6DAA6D;;YAG7D,yEAAyE;;YAGzE,2DAA2D;;YAG3D,6FAA6F;;YAG7F,4EAA4E;;YAG5E,+EAA+E;;YAG/E,6DAA6D;;YAG7D,iEAAiE;;YAGjE,4EAA4E;;YAG5E,sEAAsE;;;;;;;;;;;;;;;CAyBvE,CAAC;AAEF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration shipped with @spinajs/log ( Node only ).
|
|
3
|
+
*
|
|
4
|
+
* Everything the log package can be tuned with lives here, so the configuration
|
|
5
|
+
* module surfaces a single, discoverable list of what can be changed:
|
|
6
|
+
*
|
|
7
|
+
* 1. a DEFAULT fs provider `fs-log-default` rooted at the working process
|
|
8
|
+
* directory, so FileTarget works without any user fs configuration,
|
|
9
|
+
* 2. `logger.file` - the default FileTarget options ( buffer / rotation /
|
|
10
|
+
* retention tunables ). FileTarget merges these UNDER any per-target
|
|
11
|
+
* `options`, and a user project config ( loaded last ) overrides them - the
|
|
12
|
+
* same override chain every other spinajs package uses.
|
|
13
|
+
*
|
|
14
|
+
* Config files are merged with array concatenation, so the provider entry is
|
|
15
|
+
* APPENDED to any providers the user configures.
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_FS_PROVIDER = "fs-log-default";
|
|
18
|
+
/**
|
|
19
|
+
* Canonical default FileTarget options. This is the SINGLE source of truth for
|
|
20
|
+
* every log tunable - change a default HERE, never inline in the target or a
|
|
21
|
+
* strategy. It is exported ( not just embedded in the config below ) so the
|
|
22
|
+
* FileTarget can fall back to the exact same values when the config file is not
|
|
23
|
+
* discovered ( eg. isolated unit tests ), and so tests share one definition.
|
|
24
|
+
*/
|
|
25
|
+
export const LOG_FILE_DEFAULTS = {
|
|
26
|
+
/** fs provider holding the active log file. */
|
|
27
|
+
fs: DEFAULT_FS_PROVIDER,
|
|
28
|
+
/** Zip the archived file when it is moved to the archive. */
|
|
29
|
+
compress: false,
|
|
30
|
+
/** Rotate the active log once it grows past this many bytes ( 1 MB ). */
|
|
31
|
+
maxSize: 1024 * 1024,
|
|
32
|
+
/** Flush the in-memory buffer after this many messages. */
|
|
33
|
+
maxBufferSize: 100,
|
|
34
|
+
/** Hard cap on buffered messages; oldest are dropped past this so a down sink cannot OOM. */
|
|
35
|
+
maxQueueSize: 100000,
|
|
36
|
+
/** Periodic flush tick in milliseconds, so a partial buffer is not held. */
|
|
37
|
+
flushInterval: 1000,
|
|
38
|
+
/** How often ( seconds ) SizeLogArchiveStrategy checks the active log size. */
|
|
39
|
+
archiveInterval: 60,
|
|
40
|
+
/** Rotation trigger strategy ( decides WHEN to archive ). */
|
|
41
|
+
archiveStrategy: "SizeLogArchiveStrategy",
|
|
42
|
+
/** Retention strategies applied in order after each rotation. */
|
|
43
|
+
retentionStrategies: ["CountLogRetentionStrategy"],
|
|
44
|
+
/** Archives to keep ( CountLogRetentionStrategy ), oldest deleted first. */
|
|
45
|
+
maxArchiveFiles: 5,
|
|
46
|
+
/** Max archive age in seconds ( AgeLogRetentionStrategy ), 7 days. */
|
|
47
|
+
maxAge: 7 * 24 * 60 * 60,
|
|
48
|
+
};
|
|
49
|
+
const log = {
|
|
50
|
+
fs: {
|
|
51
|
+
defaultProvider: DEFAULT_FS_PROVIDER,
|
|
52
|
+
providers: [
|
|
53
|
+
{
|
|
54
|
+
name: DEFAULT_FS_PROVIDER,
|
|
55
|
+
service: "fsNative",
|
|
56
|
+
basePath: process.cwd(),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
logger: {
|
|
61
|
+
file: LOG_FILE_DEFAULTS,
|
|
62
|
+
perf: {
|
|
63
|
+
enabled: true,
|
|
64
|
+
thresholds: { "orm.query": 200, "http.request": 1000, default: 0 },
|
|
65
|
+
overThresholdLevel: "warn",
|
|
66
|
+
underThresholdLevel: "trace",
|
|
67
|
+
logCounters: false,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
export default log;
|
|
72
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/config/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,+CAA+C;IAC/C,EAAE,EAAE,mBAAmB;IAEvB,6DAA6D;IAC7D,QAAQ,EAAE,KAAK;IAEf,yEAAyE;IACzE,OAAO,EAAE,IAAI,GAAG,IAAI;IAEpB,2DAA2D;IAC3D,aAAa,EAAE,GAAG;IAElB,6FAA6F;IAC7F,YAAY,EAAE,MAAM;IAEpB,4EAA4E;IAC5E,aAAa,EAAE,IAAI;IAEnB,+EAA+E;IAC/E,eAAe,EAAE,EAAE;IAEnB,6DAA6D;IAC7D,eAAe,EAAE,wBAAwB;IAEzC,iEAAiE;IACjE,mBAAmB,EAAE,CAAC,2BAA2B,CAAC;IAElD,4EAA4E;IAC5E,eAAe,EAAE,CAAC;IAElB,sEAAsE;IACtE,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;CACzB,CAAC;AAEF,MAAM,GAAG,GAAG;IACV,EAAE,EAAE;QACF,eAAe,EAAE,mBAAmB;QACpC,SAAS,EAAE;YACT;gBACE,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,UAAU;gBACnB,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE;aACxB;SACF;KACF;IACD,MAAM,EAAE;QACN,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE;YACJ,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE;YAClE,kBAAkB,EAAE,MAAM;YAC1B,mBAAmB,EAAE,OAAO;YAC5B,WAAW,EAAE,KAAK;SACnB;KACF;CACF,CAAC;AAEF,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser fallback for {@link LogContext}. The browser has no
|
|
3
|
+
* `node:async_hooks` / AsyncLocalStorage, so this keeps a single module-level
|
|
4
|
+
* `current` object and swaps it synchronously around `with`.
|
|
5
|
+
*
|
|
6
|
+
* LIMITATION: there is NO async isolation here. `with` only holds the context
|
|
7
|
+
* for the synchronous portion of `fn`; anything that runs after an `await` or a
|
|
8
|
+
* deferred callback ( unless wrapped with {@link LogContextImpl.bind} ) will not
|
|
9
|
+
* see it. This mirrors the Node API surface so callers write the same code, but
|
|
10
|
+
* on the browser ambient context is best-effort and synchronous only.
|
|
11
|
+
*/
|
|
12
|
+
declare class LogContextImpl {
|
|
13
|
+
private current;
|
|
14
|
+
/**
|
|
15
|
+
* The current ambient store.
|
|
16
|
+
*/
|
|
17
|
+
active(): Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Synchronously set the context to `{ ...current, ...vars }` for the duration
|
|
20
|
+
* of `fn`, restoring the previous value afterwards. No async isolation.
|
|
21
|
+
*/
|
|
22
|
+
with<T>(vars: Record<string, unknown>, fn: () => T): T;
|
|
23
|
+
/**
|
|
24
|
+
* Mutate the current store in place ( late-bound values ).
|
|
25
|
+
*/
|
|
26
|
+
set(key: string, value: unknown): void;
|
|
27
|
+
/**
|
|
28
|
+
* Capture the current store and restore it around each invocation of the
|
|
29
|
+
* returned function.
|
|
30
|
+
*/
|
|
31
|
+
bind<A extends unknown[], R>(fn: (...a: A) => R): (...a: A) => R;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shared ambient log context ( browser, synchronous fallback ).
|
|
35
|
+
*/
|
|
36
|
+
export declare const LogContext: LogContextImpl;
|
|
37
|
+
/**
|
|
38
|
+
* Projects only primitive scalar values ( string / number / boolean / bigint )
|
|
39
|
+
* from an ambient-context object, dropping objects, arrays, Dates, functions,
|
|
40
|
+
* null and undefined. Ambient context is meant for correlation ids ( requestId,
|
|
41
|
+
* traceId, ... ) that belong on every log line; structured payloads should be
|
|
42
|
+
* passed explicitly per call ( log.info({ obj }, ... ) ), not via ambient context.
|
|
43
|
+
*/
|
|
44
|
+
export declare function scalarContext(ctx: Record<string, unknown>): Record<string, unknown>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=context.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.browser.d.ts","sourceRoot":"","sources":["../../src/context.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAA+B;IAE9C;;OAEG;IACI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIxC;;;OAGG;IACI,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAU7D;;OAEG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAI7C;;;OAGG;IACI,IAAI,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;CAYxE;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,gBAAuB,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASnF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser fallback for {@link LogContext}. The browser has no
|
|
3
|
+
* `node:async_hooks` / AsyncLocalStorage, so this keeps a single module-level
|
|
4
|
+
* `current` object and swaps it synchronously around `with`.
|
|
5
|
+
*
|
|
6
|
+
* LIMITATION: there is NO async isolation here. `with` only holds the context
|
|
7
|
+
* for the synchronous portion of `fn`; anything that runs after an `await` or a
|
|
8
|
+
* deferred callback ( unless wrapped with {@link LogContextImpl.bind} ) will not
|
|
9
|
+
* see it. This mirrors the Node API surface so callers write the same code, but
|
|
10
|
+
* on the browser ambient context is best-effort and synchronous only.
|
|
11
|
+
*/
|
|
12
|
+
class LogContextImpl {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.current = {};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The current ambient store.
|
|
18
|
+
*/
|
|
19
|
+
active() {
|
|
20
|
+
return this.current;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Synchronously set the context to `{ ...current, ...vars }` for the duration
|
|
24
|
+
* of `fn`, restoring the previous value afterwards. No async isolation.
|
|
25
|
+
*/
|
|
26
|
+
with(vars, fn) {
|
|
27
|
+
const previous = this.current;
|
|
28
|
+
this.current = { ...previous, ...vars };
|
|
29
|
+
try {
|
|
30
|
+
return fn();
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
this.current = previous;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Mutate the current store in place ( late-bound values ).
|
|
38
|
+
*/
|
|
39
|
+
set(key, value) {
|
|
40
|
+
this.current[key] = value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Capture the current store and restore it around each invocation of the
|
|
44
|
+
* returned function.
|
|
45
|
+
*/
|
|
46
|
+
bind(fn) {
|
|
47
|
+
const captured = this.current;
|
|
48
|
+
return (...args) => {
|
|
49
|
+
const previous = this.current;
|
|
50
|
+
this.current = captured;
|
|
51
|
+
try {
|
|
52
|
+
return fn(...args);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
this.current = previous;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Shared ambient log context ( browser, synchronous fallback ).
|
|
62
|
+
*/
|
|
63
|
+
export const LogContext = new LogContextImpl();
|
|
64
|
+
/**
|
|
65
|
+
* Projects only primitive scalar values ( string / number / boolean / bigint )
|
|
66
|
+
* from an ambient-context object, dropping objects, arrays, Dates, functions,
|
|
67
|
+
* null and undefined. Ambient context is meant for correlation ids ( requestId,
|
|
68
|
+
* traceId, ... ) that belong on every log line; structured payloads should be
|
|
69
|
+
* passed explicitly per call ( log.info({ obj }, ... ) ), not via ambient context.
|
|
70
|
+
*/
|
|
71
|
+
export function scalarContext(ctx) {
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const [k, v] of Object.entries(ctx)) {
|
|
74
|
+
const t = typeof v;
|
|
75
|
+
if (t === "string" || t === "number" || t === "boolean" || t === "bigint") {
|
|
76
|
+
out[k] = v;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=context.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.browser.js","sourceRoot":"","sources":["../../src/context.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,cAAc;IAApB;QACU,YAAO,GAA4B,EAAE,CAAC;IA8ChD,CAAC;IA5CC;;OAEG;IACI,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,IAAI,CAAI,IAA6B,EAAE,EAAW;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACH,OAAO,EAAE,EAAE,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW,EAAE,KAAc;QACpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,IAAI,CAAyB,EAAkB;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC9B,OAAO,CAAC,GAAG,IAAO,EAAK,EAAE;YACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;YACxB,IAAI,CAAC;gBACH,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACrB,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,EAAE,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAA4B;IACxD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC1E,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient log context backed by `node:async_hooks` AsyncLocalStorage.
|
|
3
|
+
*
|
|
4
|
+
* It deliberately resolves the SAME DI-singleton AsyncLocalStorage instance the
|
|
5
|
+
* @spinajs/http module runs per action ( `als.run(req.storage, ...)` ). Because
|
|
6
|
+
* that instance is a shared DI singleton, any log emitted anywhere inside a
|
|
7
|
+
* request automatically inherits the request store ( requestId, realIp, ... )
|
|
8
|
+
* with zero threading — the log package wires `setLogContextProvider(() =>
|
|
9
|
+
* LogContext.active())` so `createLogMessageObject` merges it at lowest
|
|
10
|
+
* precedence.
|
|
11
|
+
*
|
|
12
|
+
* The store type is a plain `Record<string, unknown>` — a superset of http's
|
|
13
|
+
* `IActionLocalStoregeContext` — so log stays independent of http.
|
|
14
|
+
*/
|
|
15
|
+
declare class LogContextImpl {
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the shared AsyncLocalStorage from DI. Resolved as a bare concrete
|
|
18
|
+
* class it is a shared singleton, so this is the very instance http drives per
|
|
19
|
+
* action. We deliberately do NOT cache the reference: DI returns the same
|
|
20
|
+
* singleton on every call ( cheap lookup ), and NOT caching keeps LogContext
|
|
21
|
+
* consistent with the current DI instance even if the container is reset /
|
|
22
|
+
* re-registered ( a stale cached reference would silently diverge — e.g. after
|
|
23
|
+
* a `DI.clearCache()` the store written via a freshly-resolved instance would
|
|
24
|
+
* be invisible here ).
|
|
25
|
+
*/
|
|
26
|
+
private storage;
|
|
27
|
+
/**
|
|
28
|
+
* The current ambient store, or an empty object when outside any context.
|
|
29
|
+
*/
|
|
30
|
+
active(): Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Run `fn` with `vars` merged ( copy-on-write ) onto the current store, so
|
|
33
|
+
* nesting accumulates and http's already-set fields ( eg. requestId ) survive.
|
|
34
|
+
*/
|
|
35
|
+
with<T>(vars: Record<string, unknown>, fn: () => T): T;
|
|
36
|
+
/**
|
|
37
|
+
* Mutate the current store in place ( late-bound values ). No-op when called
|
|
38
|
+
* outside any active context.
|
|
39
|
+
*/
|
|
40
|
+
set(key: string, value: unknown): void;
|
|
41
|
+
/**
|
|
42
|
+
* Capture the current store and re-attach it whenever the returned function is
|
|
43
|
+
* invoked. Use to carry context across detached callbacks / EventEmitter
|
|
44
|
+
* handlers that would otherwise lose it.
|
|
45
|
+
*/
|
|
46
|
+
bind<A extends unknown[], R>(fn: (...a: A) => R): (...a: A) => R;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shared ambient log context. See {@link LogContextImpl}.
|
|
50
|
+
*/
|
|
51
|
+
export declare const LogContext: LogContextImpl;
|
|
52
|
+
/**
|
|
53
|
+
* Projects only primitive scalar values ( string / number / boolean / bigint )
|
|
54
|
+
* from an ambient-context object, dropping objects, arrays, Dates, functions,
|
|
55
|
+
* null and undefined. Ambient context is meant for correlation ids ( requestId,
|
|
56
|
+
* traceId, ... ) that belong on every log line; structured payloads should be
|
|
57
|
+
* passed explicitly per call ( log.info({ obj }, ... ) ), not via ambient context.
|
|
58
|
+
*/
|
|
59
|
+
export declare function scalarContext(ctx: Record<string, unknown>): Record<string, unknown>;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,cAAM,cAAc;IAClB;;;;;;;;;OASG;IACH,OAAO,CAAC,OAAO;IAIf;;OAEG;IACI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIxC;;;OAGG;IACI,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI7D;;;OAGG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAO7C;;;;OAIG;IACI,IAAI,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;CAOxE;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,gBAAuB,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASnF"}
|