@spinajs/log 2.0.481 → 2.0.484
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 +55 -0
- package/lib/cjs/perf/LogMetricSink.d.ts.map +1 -0
- package/lib/cjs/perf/LogMetricSink.js +154 -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 +55 -0
- package/lib/mjs/perf/LogMetricSink.d.ts.map +1 -0
- package/lib/mjs/perf/LogMetricSink.js +151 -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 +26 -15
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AsyncService, Class } from "@spinajs/di";
|
|
2
|
+
import { Log } from "@spinajs/log-common";
|
|
3
|
+
import { LogArchiveStrategy } from "./archive-strategy.js";
|
|
4
|
+
import { LogRetentionStrategy } from "./retention-strategy.js";
|
|
5
|
+
import { ILogArchiveContext } from "./context.js";
|
|
6
|
+
/**
|
|
7
|
+
* Orchestrates rotation + retention for a single file log target.
|
|
8
|
+
*
|
|
9
|
+
* It owns nothing schedule-wise itself: it resolves ONE rotation strategy
|
|
10
|
+
* ( `archiveStrategy` ) and a LIST of retention strategies
|
|
11
|
+
* ( `retentionStrategies` ) by class name from DI, delegates start / stop to the
|
|
12
|
+
* rotation strategy, and provides the shared `rotate()` routine every rotation
|
|
13
|
+
* ( interval, cron or manual ) funnels through.
|
|
14
|
+
*
|
|
15
|
+
* `@NewInstance()` - each file target gets its own service ( per-target
|
|
16
|
+
* scheduling and strategy state ).
|
|
17
|
+
*/
|
|
18
|
+
export declare class LogArchiveService extends AsyncService {
|
|
19
|
+
protected Logger: Log;
|
|
20
|
+
protected ArchiveStrategy: LogArchiveStrategy;
|
|
21
|
+
protected RetentionStrategies: LogRetentionStrategy[];
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the configured rotation + retention strategies by class name.
|
|
24
|
+
* Follows the fs temp-provider mechanism: look the class up in the DI
|
|
25
|
+
* registry by name, then resolve an instance.
|
|
26
|
+
*/
|
|
27
|
+
resolve(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Wires strategies for the given context and starts the rotation schedule.
|
|
30
|
+
*/
|
|
31
|
+
start(ctx: ILogArchiveContext): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Stops the rotation schedule. Safe to call multiple times.
|
|
34
|
+
*/
|
|
35
|
+
stop(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Single rotation routine, shared by every scheduling strategy:
|
|
38
|
+
*
|
|
39
|
+
* 1. acquire the target write-lock so no append runs while we rename,
|
|
40
|
+
* 2. rename the active file to a sequenced archive name in the archive dir,
|
|
41
|
+
* 3. compress ( zip into archiveFs, drop the raw file ) OR move cross-fs,
|
|
42
|
+
* 4. run every retention strategy in order,
|
|
43
|
+
* 5. release the lock ( always, even on failure ).
|
|
44
|
+
*
|
|
45
|
+
* The whole routine is guarded so a failed rotation neither crashes the
|
|
46
|
+
* scheduler nor leaves the lock held.
|
|
47
|
+
*/
|
|
48
|
+
rotate(ctx: ILogArchiveContext): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Renames the active log file into the archive dir under a unique
|
|
51
|
+
* `archived_<name>_<seq><ext>` name. When `archiveFs` differs from `fs` the
|
|
52
|
+
* file is first renamed within `fs` then moved across.
|
|
53
|
+
*
|
|
54
|
+
* Returns the archive path relative to `archiveFs`.
|
|
55
|
+
*/
|
|
56
|
+
protected moveToArchive(ctx: ILogArchiveContext): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Zips `archived` into `archiveFs` and removes the raw archived file, so the
|
|
59
|
+
* archive dir only ever holds the compressed copy.
|
|
60
|
+
*/
|
|
61
|
+
protected compress(ctx: ILogArchiveContext, archived: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Next archive sequence number for a given base name. Uses existing archive
|
|
64
|
+
* file names first, falling back to a timestamp so two rotations in the same
|
|
65
|
+
* tick never collide.
|
|
66
|
+
*/
|
|
67
|
+
protected nextSequence(ctx: ILogArchiveContext, name: string, ext: string): Promise<number>;
|
|
68
|
+
/**
|
|
69
|
+
* Resolves a strategy instance by class name, mirroring the fs temp-provider
|
|
70
|
+
* mechanism: look the class up in the DI registry by name, then resolve an
|
|
71
|
+
* instance ( `@NewInstance()` gives a fresh per-target instance ).
|
|
72
|
+
*/
|
|
73
|
+
protected resolveStrategy<T>(base: Class<T>, className: string): T;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=LogArchiveService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogArchiveService.d.ts","sourceRoot":"","sources":["../../../src/archive/LogArchiveService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAiD,MAAM,aAAa,CAAC;AACjG,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD;;;;;;;;;;;GAWG;AACH,qBAEa,iBAAkB,SAAQ,YAAY;IAEjD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;IAEtB,SAAS,CAAC,eAAe,EAAE,kBAAkB,CAAC;IAC9C,SAAS,CAAC,mBAAmB,EAAE,oBAAoB,EAAE,CAAM;IAE3D;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC;;OAEG;IACU,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1D;;OAEG;IACI,IAAI,IAAI,IAAI;IAInB;;;;;;;;;;;OAWG;IACU,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB3D;;;;;;OAMG;cACa,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBvE;;;OAGG;cACa,QAAQ,CAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlF;;;;OAIG;cACa,YAAY,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoCjG;;;;OAIG;IACH,SAAS,CAAC,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;CAcnE"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LogArchiveService = void 0;
|
|
13
|
+
const di_1 = require("@spinajs/di");
|
|
14
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
15
|
+
const luxon_1 = require("luxon");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const archive_strategy_js_1 = require("./archive-strategy.js");
|
|
18
|
+
const retention_strategy_js_1 = require("./retention-strategy.js");
|
|
19
|
+
const util_js_1 = require("./strategies/util.js");
|
|
20
|
+
/**
|
|
21
|
+
* Orchestrates rotation + retention for a single file log target.
|
|
22
|
+
*
|
|
23
|
+
* It owns nothing schedule-wise itself: it resolves ONE rotation strategy
|
|
24
|
+
* ( `archiveStrategy` ) and a LIST of retention strategies
|
|
25
|
+
* ( `retentionStrategies` ) by class name from DI, delegates start / stop to the
|
|
26
|
+
* rotation strategy, and provides the shared `rotate()` routine every rotation
|
|
27
|
+
* ( interval, cron or manual ) funnels through.
|
|
28
|
+
*
|
|
29
|
+
* `@NewInstance()` - each file target gets its own service ( per-target
|
|
30
|
+
* scheduling and strategy state ).
|
|
31
|
+
*/
|
|
32
|
+
let LogArchiveService = class LogArchiveService extends di_1.AsyncService {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.RetentionStrategies = [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the configured rotation + retention strategies by class name.
|
|
39
|
+
* Follows the fs temp-provider mechanism: look the class up in the DI
|
|
40
|
+
* registry by name, then resolve an instance.
|
|
41
|
+
*/
|
|
42
|
+
async resolve() {
|
|
43
|
+
await super.resolve();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Wires strategies for the given context and starts the rotation schedule.
|
|
47
|
+
*/
|
|
48
|
+
async start(ctx) {
|
|
49
|
+
// archiveStrategy / retentionStrategies are populated from the logger.file
|
|
50
|
+
// config defaults ( see FileTarget.resolve ), so no inline fallback here -
|
|
51
|
+
// the config is the single source of truth for what runs.
|
|
52
|
+
this.ArchiveStrategy = this.resolveStrategy(archive_strategy_js_1.LogArchiveStrategy, ctx.options.archiveStrategy);
|
|
53
|
+
const retentionNames = ctx.options.retentionStrategies ?? [];
|
|
54
|
+
this.RetentionStrategies = retentionNames.map((n) => this.resolveStrategy(retention_strategy_js_1.LogRetentionStrategy, n));
|
|
55
|
+
this.ArchiveStrategy.start(ctx);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stops the rotation schedule. Safe to call multiple times.
|
|
59
|
+
*/
|
|
60
|
+
stop() {
|
|
61
|
+
this.ArchiveStrategy?.stop();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Single rotation routine, shared by every scheduling strategy:
|
|
65
|
+
*
|
|
66
|
+
* 1. acquire the target write-lock so no append runs while we rename,
|
|
67
|
+
* 2. rename the active file to a sequenced archive name in the archive dir,
|
|
68
|
+
* 3. compress ( zip into archiveFs, drop the raw file ) OR move cross-fs,
|
|
69
|
+
* 4. run every retention strategy in order,
|
|
70
|
+
* 5. release the lock ( always, even on failure ).
|
|
71
|
+
*
|
|
72
|
+
* The whole routine is guarded so a failed rotation neither crashes the
|
|
73
|
+
* scheduler nor leaves the lock held.
|
|
74
|
+
*/
|
|
75
|
+
async rotate(ctx) {
|
|
76
|
+
await ctx.withWriteLock(async () => {
|
|
77
|
+
// nothing written yet - nothing to rotate
|
|
78
|
+
if (!(await ctx.fs.exists(ctx.activePath))) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const archived = await this.moveToArchive(ctx);
|
|
82
|
+
if (ctx.options.compress) {
|
|
83
|
+
await this.compress(ctx, archived);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// retention runs OUTSIDE the write-lock - it only touches archive files,
|
|
87
|
+
// never the active log, so it must not block appends.
|
|
88
|
+
for (const strategy of this.RetentionStrategies) {
|
|
89
|
+
await strategy.safePrune(ctx);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Renames the active log file into the archive dir under a unique
|
|
94
|
+
* `archived_<name>_<seq><ext>` name. When `archiveFs` differs from `fs` the
|
|
95
|
+
* file is first renamed within `fs` then moved across.
|
|
96
|
+
*
|
|
97
|
+
* Returns the archive path relative to `archiveFs`.
|
|
98
|
+
*/
|
|
99
|
+
async moveToArchive(ctx) {
|
|
100
|
+
const { name, ext } = (0, path_1.parse)(path_1.posix.basename(ctx.activePath.replace(/\\/g, "/")));
|
|
101
|
+
const seq = await this.nextSequence(ctx, name, ext);
|
|
102
|
+
const archiveName = `${util_js_1.ARCHIVE_PREFIX}${name}_${seq}${ext}`;
|
|
103
|
+
const archiveRel = (0, util_js_1.archivePath)(ctx, archiveName);
|
|
104
|
+
if (ctx.archiveFs === ctx.fs) {
|
|
105
|
+
await ctx.fs.rename(ctx.activePath, archiveRel);
|
|
106
|
+
return archiveRel;
|
|
107
|
+
}
|
|
108
|
+
// cross-fs: rename to a temp name inside `fs`, then move into archiveFs
|
|
109
|
+
const stagingRel = `${util_js_1.ARCHIVE_PREFIX}${name}_${seq}${ext}`;
|
|
110
|
+
await ctx.fs.rename(ctx.activePath, stagingRel);
|
|
111
|
+
await ctx.fs.move(stagingRel, archiveRel, ctx.archiveFs);
|
|
112
|
+
return archiveRel;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Zips `archived` into `archiveFs` and removes the raw archived file, so the
|
|
116
|
+
* archive dir only ever holds the compressed copy.
|
|
117
|
+
*/
|
|
118
|
+
async compress(ctx, archived) {
|
|
119
|
+
const zipRel = `${archived}.zip`;
|
|
120
|
+
// zip() honors a non-temp dstFs / dstFile - output lands directly in archiveFs
|
|
121
|
+
await ctx.archiveFs.zip(archived, ctx.archiveFs, zipRel);
|
|
122
|
+
await ctx.archiveFs.rm(archived);
|
|
123
|
+
this.Logger.trace(`Compressed archive ${archived} -> ${zipRel}`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Next archive sequence number for a given base name. Uses existing archive
|
|
127
|
+
* file names first, falling back to a timestamp so two rotations in the same
|
|
128
|
+
* tick never collide.
|
|
129
|
+
*/
|
|
130
|
+
async nextSequence(ctx, name, ext) {
|
|
131
|
+
let existing = [];
|
|
132
|
+
try {
|
|
133
|
+
existing = await ctx.archiveFs.list(ctx.archiveDir || "/");
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
existing = [];
|
|
137
|
+
}
|
|
138
|
+
const prefix = `${util_js_1.ARCHIVE_PREFIX}${name}_`;
|
|
139
|
+
// prefix is escaped via escapeRegExp before interpolation
|
|
140
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
141
|
+
const seqReg = new RegExp(`^${escapeRegExp(prefix)}(\\d+)`);
|
|
142
|
+
let max = 0;
|
|
143
|
+
for (const f of existing) {
|
|
144
|
+
const m = seqReg.exec(f);
|
|
145
|
+
if (m) {
|
|
146
|
+
const n = parseInt(m[1], 10);
|
|
147
|
+
if (n > max) {
|
|
148
|
+
max = n;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const next = max + 1;
|
|
153
|
+
// guard against a name clash ( eg. same-second cron + size rotation ) by
|
|
154
|
+
// appending a millisecond timestamp only when the computed name already exists
|
|
155
|
+
const candidate = (0, util_js_1.archivePath)(ctx, `${util_js_1.ARCHIVE_PREFIX}${name}_${next}${ext}`);
|
|
156
|
+
if (await ctx.archiveFs.exists(candidate)) {
|
|
157
|
+
return luxon_1.DateTime.now().toMillis();
|
|
158
|
+
}
|
|
159
|
+
return next;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Resolves a strategy instance by class name, mirroring the fs temp-provider
|
|
163
|
+
* mechanism: look the class up in the DI registry by name, then resolve an
|
|
164
|
+
* instance ( `@NewInstance()` gives a fresh per-target instance ).
|
|
165
|
+
*/
|
|
166
|
+
resolveStrategy(base, className) {
|
|
167
|
+
const types = di_1.DI.RootContainer.Registry.getTypes(base);
|
|
168
|
+
const type = types.find((x) => x.name === className);
|
|
169
|
+
if (!type) {
|
|
170
|
+
const baseName = base.name;
|
|
171
|
+
throw new di_1.ResolveException(`Log archive strategy ${className} ( ${baseName} ) not registered, make sure it is imported and registered in DI container`);
|
|
172
|
+
}
|
|
173
|
+
// strategies are plain ( non-async ) services, so resolve is synchronous
|
|
174
|
+
return di_1.DI.resolve(type);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
exports.LogArchiveService = LogArchiveService;
|
|
178
|
+
__decorate([
|
|
179
|
+
(0, log_common_1.Logger)("LogFileTarget"),
|
|
180
|
+
__metadata("design:type", log_common_1.Log)
|
|
181
|
+
], LogArchiveService.prototype, "Logger", void 0);
|
|
182
|
+
exports.LogArchiveService = LogArchiveService = __decorate([
|
|
183
|
+
(0, di_1.Injectable)(),
|
|
184
|
+
(0, di_1.NewInstance)()
|
|
185
|
+
], LogArchiveService);
|
|
186
|
+
function escapeRegExp(s) {
|
|
187
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=LogArchiveService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogArchiveService.js","sourceRoot":"","sources":["../../../src/archive/LogArchiveService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAiG;AACjG,o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B,CA0K7B;AAED,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Log } from "@spinajs/log-common";
|
|
2
|
+
import { ILogArchiveContext } from "./context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rotation policy for a file log target. Decides WHEN the active log file is
|
|
5
|
+
* rotated ( moved to the archive ) and owns its own schedule - the scheduling
|
|
6
|
+
* mechanism ( interval, cron, ... ) is strategy specific and implemented in
|
|
7
|
+
* `start` / `stop`.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the shape of fs `TempCleanupStrategy`: strategies hold per-target
|
|
10
|
+
* scheduling state, so implementations MUST be registered with `@NewInstance()`
|
|
11
|
+
* - otherwise a single instance would be shared between all file targets.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class LogArchiveStrategy {
|
|
14
|
+
protected Logger: Log;
|
|
15
|
+
/**
|
|
16
|
+
* Starts scheduled rotation. How rotations are scheduled is up to the
|
|
17
|
+
* strategy.
|
|
18
|
+
*
|
|
19
|
+
* @param ctx archive context of the file target
|
|
20
|
+
*/
|
|
21
|
+
abstract start(ctx: ILogArchiveContext): void;
|
|
22
|
+
/**
|
|
23
|
+
* Stops scheduled rotation. Safe to call multiple times.
|
|
24
|
+
*/
|
|
25
|
+
abstract stop(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Single rotation trigger guarded against errors - a failed rotation ( disk
|
|
28
|
+
* full, remote backend down, ... ) must never crash the scheduler tick.
|
|
29
|
+
*/
|
|
30
|
+
protected triggerRotation(ctx: ILogArchiveContext): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=archive-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive-strategy.d.ts","sourceRoot":"","sources":["../../../src/archive/archive-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;GASG;AACH,8BAAsB,kBAAkB;IAEtC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;IAEtB;;;;;OAKG;aACa,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI;IAEpD;;OAEG;aACa,IAAI,IAAI,IAAI;IAE5B;;;OAGG;cACa,eAAe,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LogArchiveStrategy = void 0;
|
|
13
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
14
|
+
/**
|
|
15
|
+
* Rotation policy for a file log target. Decides WHEN the active log file is
|
|
16
|
+
* rotated ( moved to the archive ) and owns its own schedule - the scheduling
|
|
17
|
+
* mechanism ( interval, cron, ... ) is strategy specific and implemented in
|
|
18
|
+
* `start` / `stop`.
|
|
19
|
+
*
|
|
20
|
+
* Mirrors the shape of fs `TempCleanupStrategy`: strategies hold per-target
|
|
21
|
+
* scheduling state, so implementations MUST be registered with `@NewInstance()`
|
|
22
|
+
* - otherwise a single instance would be shared between all file targets.
|
|
23
|
+
*/
|
|
24
|
+
class LogArchiveStrategy {
|
|
25
|
+
/**
|
|
26
|
+
* Single rotation trigger guarded against errors - a failed rotation ( disk
|
|
27
|
+
* full, remote backend down, ... ) must never crash the scheduler tick.
|
|
28
|
+
*/
|
|
29
|
+
async triggerRotation(ctx) {
|
|
30
|
+
try {
|
|
31
|
+
await ctx.rotate();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
this.Logger.warn(`Log rotation for target ${ctx.options.path} failed: ${err.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.LogArchiveStrategy = LogArchiveStrategy;
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, log_common_1.Logger)("LogFileTarget"),
|
|
41
|
+
__metadata("design:type", log_common_1.Log)
|
|
42
|
+
], LogArchiveStrategy.prototype, "Logger", void 0);
|
|
43
|
+
//# sourceMappingURL=archive-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive-strategy.js","sourceRoot":"","sources":["../../../src/archive/archive-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkD;AAGlD;;;;;;;;;GASG;AACH,MAAsB,kBAAkB;IAiBtC;;;OAGG;IACO,KAAK,CAAC,eAAe,CAAC,GAAuB;QACrD,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,GAAG,CAAC,OAAO,CAAC,IAAI,YAAa,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QACpG,CAAC;IACH,CAAC;CACF;AA5BD,gDA4BC;AA1BW;IADT,IAAA,mBAAM,EAAC,eAAe,CAAC;8BACN,gBAAG;kDAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { fs } from "@spinajs/fs";
|
|
2
|
+
import { Log, IFileTargetOptions } from "@spinajs/log-common";
|
|
3
|
+
/**
|
|
4
|
+
* Shared context handed to every archive / retention strategy.
|
|
5
|
+
*
|
|
6
|
+
* It exposes the filesystems and paths a strategy needs, plus the two
|
|
7
|
+
* cross-cutting hooks it must go through:
|
|
8
|
+
*
|
|
9
|
+
* - `rotate()` - perform a single rotation ( owned by LogArchiveService ),
|
|
10
|
+
* - `withWriteLock()` - run a critical section under the target write-lock so
|
|
11
|
+
* a rename never races an in-flight append.
|
|
12
|
+
*/
|
|
13
|
+
export interface ILogArchiveContext {
|
|
14
|
+
/**
|
|
15
|
+
* Filesystem holding the ACTIVE log file.
|
|
16
|
+
*/
|
|
17
|
+
fs: fs;
|
|
18
|
+
/**
|
|
19
|
+
* Filesystem archives ( rotated / zipped files ) are moved to. Defaults to
|
|
20
|
+
* the same provider as `fs`.
|
|
21
|
+
*/
|
|
22
|
+
archiveFs: fs;
|
|
23
|
+
/**
|
|
24
|
+
* Path ( relative to `fs` base path ) of the active log file.
|
|
25
|
+
*/
|
|
26
|
+
activePath: string;
|
|
27
|
+
/**
|
|
28
|
+
* Directory ( relative to `archiveFs` base path ) archives are stored in.
|
|
29
|
+
*/
|
|
30
|
+
archiveDir: string;
|
|
31
|
+
/**
|
|
32
|
+
* Resolved file target options ( maxSize, maxAge, compress, ... ).
|
|
33
|
+
*/
|
|
34
|
+
options: IFileTargetOptions["options"];
|
|
35
|
+
/**
|
|
36
|
+
* Target logger, used for diagnostics.
|
|
37
|
+
*/
|
|
38
|
+
logger: Log;
|
|
39
|
+
/**
|
|
40
|
+
* Perform a single rotation of the active log file. Implemented by
|
|
41
|
+
* LogArchiveService - strategies call this from their schedule.
|
|
42
|
+
*/
|
|
43
|
+
rotate(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Run `fn` under the target write-lock so it cannot overlap with an
|
|
46
|
+
* in-flight append / flush.
|
|
47
|
+
*/
|
|
48
|
+
withWriteLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/archive/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,EAAE,EAAE,EAAE,CAAC;IAEP;;;OAGG;IACH,SAAS,EAAE,EAAE,CAAC;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEvC;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC;IAEZ;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;OAGG;IACH,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/archive/context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./context.js";
|
|
2
|
+
export * from "./archive-strategy.js";
|
|
3
|
+
export * from "./retention-strategy.js";
|
|
4
|
+
export * from "./LogArchiveService.js";
|
|
5
|
+
export * from "./strategies/util.js";
|
|
6
|
+
export * from "./strategies/SizeLogArchiveStrategy.js";
|
|
7
|
+
export * from "./strategies/CronLogArchiveStrategy.js";
|
|
8
|
+
export * from "./strategies/CountLogRetentionStrategy.js";
|
|
9
|
+
export * from "./strategies/AgeLogRetentionStrategy.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/archive/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context.js"), exports);
|
|
18
|
+
__exportStar(require("./archive-strategy.js"), exports);
|
|
19
|
+
__exportStar(require("./retention-strategy.js"), exports);
|
|
20
|
+
__exportStar(require("./LogArchiveService.js"), exports);
|
|
21
|
+
__exportStar(require("./strategies/util.js"), exports);
|
|
22
|
+
__exportStar(require("./strategies/SizeLogArchiveStrategy.js"), exports);
|
|
23
|
+
__exportStar(require("./strategies/CronLogArchiveStrategy.js"), exports);
|
|
24
|
+
__exportStar(require("./strategies/CountLogRetentionStrategy.js"), exports);
|
|
25
|
+
__exportStar(require("./strategies/AgeLogRetentionStrategy.js"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/archive/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,wDAAsC;AACtC,0DAAwC;AACxC,yDAAuC;AACvC,uDAAqC;AACrC,yEAAuD;AACvD,yEAAuD;AACvD,4EAA0D;AAC1D,0EAAwD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Log } from "@spinajs/log-common";
|
|
2
|
+
import { ILogArchiveContext } from "./context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Retention policy for archived log files. Decides WHICH archives are deleted
|
|
5
|
+
* after a rotation ( eg. keep newest N, drop older than maxAge ).
|
|
6
|
+
*
|
|
7
|
+
* Retention strategies are composable - a file target applies a LIST of them in
|
|
8
|
+
* sequence, so count + age can be combined. Each concrete strategy is
|
|
9
|
+
* `@NewInstance()` to keep per-target state isolated, mirroring the fs cleanup
|
|
10
|
+
* strategies.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class LogRetentionStrategy {
|
|
13
|
+
protected Logger: Log;
|
|
14
|
+
/**
|
|
15
|
+
* Removes archives from `ctx.archiveDir` according to the strategy policy.
|
|
16
|
+
*
|
|
17
|
+
* @param ctx archive context of the file target
|
|
18
|
+
*/
|
|
19
|
+
abstract prune(ctx: ILogArchiveContext): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Single prune guarded against errors so one failing retention strategy never
|
|
22
|
+
* aborts the rest of the retention list or the rotation routine.
|
|
23
|
+
*/
|
|
24
|
+
safePrune(ctx: ILogArchiveContext): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=retention-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-strategy.d.ts","sourceRoot":"","sources":["../../../src/archive/retention-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;GAQG;AACH,8BAAsB,oBAAoB;IAExC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC;IAEtB;;;;OAIG;aACa,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D;;;OAGG;IACU,SAAS,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAO/D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LogRetentionStrategy = void 0;
|
|
13
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
14
|
+
/**
|
|
15
|
+
* Retention policy for archived log files. Decides WHICH archives are deleted
|
|
16
|
+
* after a rotation ( eg. keep newest N, drop older than maxAge ).
|
|
17
|
+
*
|
|
18
|
+
* Retention strategies are composable - a file target applies a LIST of them in
|
|
19
|
+
* sequence, so count + age can be combined. Each concrete strategy is
|
|
20
|
+
* `@NewInstance()` to keep per-target state isolated, mirroring the fs cleanup
|
|
21
|
+
* strategies.
|
|
22
|
+
*/
|
|
23
|
+
class LogRetentionStrategy {
|
|
24
|
+
/**
|
|
25
|
+
* Single prune guarded against errors so one failing retention strategy never
|
|
26
|
+
* aborts the rest of the retention list or the rotation routine.
|
|
27
|
+
*/
|
|
28
|
+
async safePrune(ctx) {
|
|
29
|
+
try {
|
|
30
|
+
await this.prune(ctx);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
this.Logger.warn(`Log retention for target ${ctx.options.path} failed: ${err.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.LogRetentionStrategy = LogRetentionStrategy;
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, log_common_1.Logger)("LogFileTarget"),
|
|
40
|
+
__metadata("design:type", log_common_1.Log)
|
|
41
|
+
], LogRetentionStrategy.prototype, "Logger", void 0);
|
|
42
|
+
//# sourceMappingURL=retention-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention-strategy.js","sourceRoot":"","sources":["../../../src/archive/retention-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkD;AAGlD;;;;;;;;GAQG;AACH,MAAsB,oBAAoB;IAWxC;;;OAGG;IACI,KAAK,CAAC,SAAS,CAAC,GAAuB;QAC5C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,GAAG,CAAC,OAAO,CAAC,IAAI,YAAa,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;CACF;AAtBD,oDAsBC;AApBW;IADT,IAAA,mBAAM,EAAC,eAAe,CAAC;8BACN,gBAAG;oDAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogRetentionStrategy } from "../retention-strategy.js";
|
|
2
|
+
import { ILogArchiveContext } from "../context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Deletes archives older than `maxAge` seconds ( from the logger.file config
|
|
5
|
+
* defaults ). Age is taken from the archive modification time.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AgeLogRetentionStrategy extends LogRetentionStrategy {
|
|
8
|
+
prune(ctx: ILogArchiveContext): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=AgeLogRetentionStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgeLogRetentionStrategy.d.ts","sourceRoot":"","sources":["../../../../src/archive/strategies/AgeLogRetentionStrategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD;;;GAGG;AACH,qBAEa,uBAAwB,SAAQ,oBAAoB;IAClD,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAuB3D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AgeLogRetentionStrategy = void 0;
|
|
10
|
+
const di_1 = require("@spinajs/di");
|
|
11
|
+
const luxon_1 = require("luxon");
|
|
12
|
+
const retention_strategy_js_1 = require("../retention-strategy.js");
|
|
13
|
+
const util_js_1 = require("./util.js");
|
|
14
|
+
/**
|
|
15
|
+
* Deletes archives older than `maxAge` seconds ( from the logger.file config
|
|
16
|
+
* defaults ). Age is taken from the archive modification time.
|
|
17
|
+
*/
|
|
18
|
+
let AgeLogRetentionStrategy = class AgeLogRetentionStrategy extends retention_strategy_js_1.LogRetentionStrategy {
|
|
19
|
+
async prune(ctx) {
|
|
20
|
+
// maxAge is always populated from the config defaults ( see logger.file )
|
|
21
|
+
const maxAge = ctx.options.maxAge;
|
|
22
|
+
const now = luxon_1.DateTime.now();
|
|
23
|
+
const archives = await (0, util_js_1.listArchives)(ctx);
|
|
24
|
+
for (const a of archives) {
|
|
25
|
+
const ts = a.stat.ModifiedTime;
|
|
26
|
+
if (!ts || !ts.isValid) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (now.diff(ts, "seconds").seconds > maxAge) {
|
|
30
|
+
try {
|
|
31
|
+
this.Logger.trace(`Deleting archive ${a.path} ( older than ${maxAge}s )`);
|
|
32
|
+
await ctx.archiveFs.rm(a.path);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
this.Logger.warn(`Cannot delete archive ${a.path}: ${err.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.AgeLogRetentionStrategy = AgeLogRetentionStrategy;
|
|
42
|
+
exports.AgeLogRetentionStrategy = AgeLogRetentionStrategy = __decorate([
|
|
43
|
+
(0, di_1.Injectable)(retention_strategy_js_1.LogRetentionStrategy),
|
|
44
|
+
(0, di_1.NewInstance)()
|
|
45
|
+
], AgeLogRetentionStrategy);
|
|
46
|
+
//# sourceMappingURL=AgeLogRetentionStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgeLogRetentionStrategy.js","sourceRoot":"","sources":["../../../../src/archive/strategies/AgeLogRetentionStrategy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oCAAsD;AACtD,iCAAiC;AACjC,oEAAgE;AAEhE,uCAAyC;AAEzC;;;GAGG;AAGI,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,4CAAoB;IACxD,KAAK,CAAC,KAAK,CAAC,GAAuB;QACxC,0EAA0E;QAC1E,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,MAAgB,CAAC;QAC5C,MAAM,GAAG,GAAG,gBAAQ,CAAC,GAAG,EAAE,CAAC;QAE3B,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAY,EAAC,GAAG,CAAC,CAAC;QAEzC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;YAC/B,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;gBACvB,SAAS;YACX,CAAC;YAED,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;gBAC7C,IAAI,CAAC;oBACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,IAAI,iBAAiB,MAAM,KAAK,CAAC,CAAC;oBAC1E,MAAM,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACjC,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;gBACjF,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAxBY,0DAAuB;kCAAvB,uBAAuB;IAFnC,IAAA,eAAU,EAAC,4CAAoB,CAAC;IAChC,IAAA,gBAAW,GAAE;GACD,uBAAuB,CAwBnC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogRetentionStrategy } from "../retention-strategy.js";
|
|
2
|
+
import { ILogArchiveContext } from "../context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the newest N archives ( `maxArchiveFiles`, from the logger.file config
|
|
5
|
+
* defaults ) and deletes the oldest, ordered by modification time.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CountLogRetentionStrategy extends LogRetentionStrategy {
|
|
8
|
+
prune(ctx: ILogArchiveContext): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=CountLogRetentionStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CountLogRetentionStrategy.d.ts","sourceRoot":"","sources":["../../../../src/archive/strategies/CountLogRetentionStrategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD;;;GAGG;AACH,qBAEa,yBAA0B,SAAQ,oBAAoB;IACpD,KAAK,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAqB3D"}
|