zario 0.4.5 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +139 -102
- package/dist/aggregation/LogAggregator.cjs +161 -0
- package/dist/aggregation/LogAggregator.d.cts +6 -0
- package/dist/aggregation/LogAggregator.d.ts +6 -0
- package/dist/aggregation/LogAggregator.js +134 -0
- package/dist/aggregation/index.cjs +163 -0
- package/dist/aggregation/index.d.cts +6 -0
- package/dist/aggregation/index.d.ts +6 -0
- package/dist/aggregation/index.js +134 -0
- package/dist/context/RequestContext.cjs +68 -0
- package/dist/context/RequestContext.d.cts +16 -0
- package/dist/context/RequestContext.d.ts +16 -0
- package/dist/context/RequestContext.js +43 -0
- package/dist/context/index.cjs +70 -0
- package/dist/context/index.d.cts +2 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +43 -0
- package/dist/core/CustomLogLevel.cjs +18 -0
- package/dist/core/CustomLogLevel.d.cts +9 -0
- package/dist/core/CustomLogLevel.d.ts +9 -0
- package/dist/core/CustomLogLevel.js +0 -0
- package/dist/core/Formatter.cjs +231 -0
- package/dist/core/Formatter.d.cts +6 -0
- package/dist/core/Formatter.d.ts +6 -0
- package/dist/core/Formatter.js +204 -0
- package/dist/core/LogLevel.cjs +18 -0
- package/dist/core/LogLevel.d.cts +3 -0
- package/dist/core/LogLevel.d.ts +3 -0
- package/dist/core/LogLevel.js +0 -0
- package/dist/core/Logger.cjs +796 -0
- package/dist/core/Logger.d.cts +6 -0
- package/dist/core/Logger.d.ts +6 -0
- package/dist/core/Logger.js +769 -0
- package/dist/filters/Filter.cjs +122 -0
- package/dist/filters/Filter.d.cts +6 -0
- package/dist/filters/Filter.d.ts +6 -0
- package/dist/filters/Filter.js +90 -0
- package/dist/filters/index.cjs +124 -0
- package/dist/filters/index.d.cts +6 -0
- package/dist/filters/index.d.ts +6 -0
- package/dist/filters/index.js +90 -0
- package/dist/index-BQ3Wnw2M.d.ts +424 -0
- package/dist/index-BRrRLU1p.d.cts +424 -0
- package/dist/index.cjs +2233 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +2175 -0
- package/dist/logger.cjs +800 -0
- package/dist/logger.d.cts +13 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +773 -0
- package/dist/otel/OTelContextProvider.cjs +117 -0
- package/dist/otel/OTelContextProvider.d.cts +18 -0
- package/dist/otel/OTelContextProvider.d.ts +18 -0
- package/dist/otel/OTelContextProvider.js +95 -0
- package/dist/otel/index.cjs +119 -0
- package/dist/otel/index.d.cts +2 -0
- package/dist/otel/index.d.ts +2 -0
- package/dist/otel/index.js +95 -0
- package/dist/structured/StructuredExtensions.cjs +279 -0
- package/dist/structured/StructuredExtensions.d.cts +6 -0
- package/dist/structured/StructuredExtensions.d.ts +6 -0
- package/dist/structured/StructuredExtensions.js +250 -0
- package/dist/structured/index.cjs +281 -0
- package/dist/structured/index.d.cts +6 -0
- package/dist/structured/index.d.ts +6 -0
- package/dist/structured/index.js +250 -0
- package/dist/transports/CircuitBreakerTransport.cjs +203 -0
- package/dist/transports/CircuitBreakerTransport.d.cts +49 -0
- package/dist/{esm/transports → transports}/CircuitBreakerTransport.d.ts +13 -7
- package/dist/transports/CircuitBreakerTransport.js +178 -0
- package/dist/transports/ConsoleTransport.cjs +55 -0
- package/dist/transports/ConsoleTransport.d.cts +18 -0
- package/dist/transports/ConsoleTransport.d.ts +18 -0
- package/dist/transports/ConsoleTransport.js +30 -0
- package/dist/transports/DeadLetterQueue.cjs +147 -0
- package/dist/transports/DeadLetterQueue.d.cts +41 -0
- package/dist/{esm/transports → transports}/DeadLetterQueue.d.ts +15 -8
- package/dist/transports/DeadLetterQueue.js +112 -0
- package/dist/transports/FileTransport.cjs +280 -0
- package/dist/transports/FileTransport.d.cts +6 -0
- package/dist/transports/FileTransport.d.ts +6 -0
- package/dist/transports/FileTransport.js +245 -0
- package/dist/transports/FilterableTransport.cjs +57 -0
- package/dist/transports/FilterableTransport.d.cts +19 -0
- package/dist/transports/FilterableTransport.d.ts +19 -0
- package/dist/transports/FilterableTransport.js +32 -0
- package/dist/transports/HttpTransport.cjs +164 -0
- package/dist/transports/HttpTransport.d.cts +36 -0
- package/dist/transports/HttpTransport.d.ts +36 -0
- package/dist/transports/HttpTransport.js +129 -0
- package/dist/transports/RetryTransport.cjs +243 -0
- package/dist/transports/RetryTransport.d.cts +6 -0
- package/dist/transports/RetryTransport.d.ts +6 -0
- package/dist/transports/RetryTransport.js +217 -0
- package/dist/transports/Transport.cjs +18 -0
- package/dist/transports/Transport.d.cts +6 -0
- package/dist/transports/Transport.d.ts +6 -0
- package/dist/transports/Transport.js +0 -0
- package/dist/transports/index.cjs +981 -0
- package/dist/transports/index.d.cts +11 -0
- package/dist/transports/index.d.ts +11 -0
- package/dist/transports/index.js +937 -0
- package/dist/types/OpenTelemetryTypes.cjs +18 -0
- package/dist/types/OpenTelemetryTypes.d.cts +60 -0
- package/dist/types/OpenTelemetryTypes.d.ts +60 -0
- package/dist/types/OpenTelemetryTypes.js +0 -0
- package/dist/types/TypeInterfaces.cjs +18 -0
- package/dist/types/TypeInterfaces.d.cts +9 -0
- package/dist/types/TypeInterfaces.d.ts +9 -0
- package/dist/types/TypeInterfaces.js +0 -0
- package/dist/types/index.d.cjs +18 -0
- package/dist/types/index.d.d.cts +6 -0
- package/dist/types/index.d.d.ts +6 -0
- package/dist/types/index.d.js +0 -0
- package/dist/utils/BufferedWriteStream.cjs +160 -0
- package/dist/utils/BufferedWriteStream.d.cts +27 -0
- package/dist/utils/BufferedWriteStream.d.ts +27 -0
- package/dist/utils/BufferedWriteStream.js +125 -0
- package/dist/utils/ColorUtil.cjs +79 -0
- package/dist/utils/ColorUtil.d.cts +9 -0
- package/dist/utils/ColorUtil.d.ts +9 -0
- package/dist/utils/ColorUtil.js +54 -0
- package/dist/utils/Redactor.cjs +73 -0
- package/dist/utils/Redactor.d.cts +42 -0
- package/dist/utils/Redactor.d.ts +42 -0
- package/dist/utils/Redactor.js +48 -0
- package/dist/utils/TimeUtil.cjs +66 -0
- package/dist/utils/TimeUtil.d.cts +5 -0
- package/dist/utils/TimeUtil.d.ts +5 -0
- package/dist/utils/TimeUtil.js +41 -0
- package/dist/utils/Timer.cjs +46 -0
- package/dist/utils/Timer.d.cts +10 -0
- package/dist/utils/Timer.d.ts +10 -0
- package/dist/utils/Timer.js +21 -0
- package/dist/utils/index.cjs +278 -0
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +238 -0
- package/package.json +93 -87
- package/dist/cjs/aggregation/LogAggregator.js +0 -139
- package/dist/cjs/aggregation/index.js +0 -17
- package/dist/cjs/core/CustomLogLevel.js +0 -2
- package/dist/cjs/core/Formatter.js +0 -74
- package/dist/cjs/core/LogLevel.js +0 -2
- package/dist/cjs/core/Logger.js +0 -355
- package/dist/cjs/filters/Filter.js +0 -90
- package/dist/cjs/filters/index.js +0 -17
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/structured/StructuredExtensions.js +0 -112
- package/dist/cjs/structured/index.js +0 -17
- package/dist/cjs/transports/CircuitBreakerTransport.js +0 -171
- package/dist/cjs/transports/ConsoleTransport.js +0 -39
- package/dist/cjs/transports/DeadLetterQueue.js +0 -129
- package/dist/cjs/transports/FileTransport.js +0 -331
- package/dist/cjs/transports/FilterableTransport.js +0 -39
- package/dist/cjs/transports/HttpTransport.js +0 -162
- package/dist/cjs/transports/RetryTransport.js +0 -199
- package/dist/cjs/transports/Transport.js +0 -2
- package/dist/cjs/transports/index.js +0 -24
- package/dist/cjs/types/TypeInterfaces.js +0 -2
- package/dist/cjs/utils/index.js +0 -78
- package/dist/esm/aggregation/LogAggregator.d.ts +0 -39
- package/dist/esm/aggregation/LogAggregator.js +0 -133
- package/dist/esm/aggregation/index.d.ts +0 -1
- package/dist/esm/aggregation/index.js +0 -1
- package/dist/esm/core/CustomLogLevel.d.ts +0 -6
- package/dist/esm/core/CustomLogLevel.js +0 -1
- package/dist/esm/core/Formatter.d.ts +0 -29
- package/dist/esm/core/Formatter.js +0 -70
- package/dist/esm/core/LogLevel.d.ts +0 -1
- package/dist/esm/core/LogLevel.js +0 -1
- package/dist/esm/core/Logger.d.ts +0 -109
- package/dist/esm/core/Logger.js +0 -351
- package/dist/esm/filters/Filter.d.ts +0 -49
- package/dist/esm/filters/Filter.js +0 -79
- package/dist/esm/filters/index.d.ts +0 -1
- package/dist/esm/filters/index.js +0 -1
- package/dist/esm/index.d.ts +0 -12
- package/dist/esm/index.js +0 -25
- package/dist/esm/structured/StructuredExtensions.d.ts +0 -31
- package/dist/esm/structured/StructuredExtensions.js +0 -74
- package/dist/esm/structured/index.d.ts +0 -1
- package/dist/esm/structured/index.js +0 -1
- package/dist/esm/transports/CircuitBreakerTransport.js +0 -167
- package/dist/esm/transports/ConsoleTransport.d.ts +0 -12
- package/dist/esm/transports/ConsoleTransport.js +0 -35
- package/dist/esm/transports/DeadLetterQueue.js +0 -92
- package/dist/esm/transports/FileTransport.d.ts +0 -45
- package/dist/esm/transports/FileTransport.js +0 -294
- package/dist/esm/transports/FilterableTransport.d.ts +0 -14
- package/dist/esm/transports/FilterableTransport.js +0 -35
- package/dist/esm/transports/HttpTransport.d.ts +0 -26
- package/dist/esm/transports/HttpTransport.js +0 -125
- package/dist/esm/transports/RetryTransport.d.ts +0 -67
- package/dist/esm/transports/RetryTransport.js +0 -195
- package/dist/esm/transports/Transport.d.ts +0 -7
- package/dist/esm/transports/Transport.js +0 -1
- package/dist/esm/transports/index.d.ts +0 -8
- package/dist/esm/transports/index.js +0 -8
- package/dist/esm/types/TypeInterfaces.d.ts +0 -7
- package/dist/esm/types/TypeInterfaces.js +0 -1
- package/dist/esm/utils/index.d.ts +0 -15
- package/dist/esm/utils/index.js +0 -72
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Damilare Osibanjo
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Damilare Osibanjo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,102 +1,139 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
<a id="top"></a>
|
|
4
|
-
|
|
5
|
-
# 📝 Zario
|
|
6
|
-
|
|
7
|
-
###
|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/zario)
|
|
10
|
-
[](./LICENSE)
|
|
11
|
-
[](https://www.npmjs.com/package/zario)
|
|
12
|
-
[](https://bundlephobia.com/package/zario)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
logger.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<a id="top"></a>
|
|
4
|
+
|
|
5
|
+
# 📝 Zario
|
|
6
|
+
|
|
7
|
+
### Fast and simple logging library for TypeScript
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/zario)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
[](https://www.npmjs.com/package/zario)
|
|
12
|
+
[](https://bundlephobia.com/package/zario)
|
|
13
|
+
|
|
14
|
+
[Japanese](README-JP.md)
|
|
15
|
+
|
|
16
|
+
<br/>
|
|
17
|
+
|
|
18
|
+
**Fast** • **Simple** • **Zero Dependencies** • **TypeScript Native**
|
|
19
|
+
|
|
20
|
+
<br/>
|
|
21
|
+
|
|
22
|
+
[⚡ Quick Start](#-quick-start) · [📖 Documentation](#-documentation) · [🤝 Contributing](#-contributing)
|
|
23
|
+
|
|
24
|
+
<br/>
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<br/>
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Zero dependencies** — nothing to install, nothing to break
|
|
35
|
+
- **Simple API** — `logger.info()`, `logger.warn()`, `logger.error()`
|
|
36
|
+
- **Flexible formatting** — plain text or structured JSON
|
|
37
|
+
- **Multiple transports** — Console, File (rotation + compression), HTTP (with retry)
|
|
38
|
+
- **Child loggers** — scoped logging for modules or requests
|
|
39
|
+
- **Async mode** — non-blocking writes for high-throughput apps
|
|
40
|
+
- **Customizable** — custom log levels, colors, and filters
|
|
41
|
+
|
|
42
|
+
## 📦 Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install zario
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 🚀 Quick Start
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { Logger, ConsoleTransport } from "zario";
|
|
52
|
+
|
|
53
|
+
const logger = new Logger({
|
|
54
|
+
level: "info",
|
|
55
|
+
colorize: true,
|
|
56
|
+
transports: [new ConsoleTransport()],
|
|
57
|
+
prefix: "[MyApp]",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
logger.info("Server started on port 3000");
|
|
61
|
+
logger.warn("High memory usage detected");
|
|
62
|
+
logger.error("Database connection failed", { code: 500 });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Child Logger
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const requestLogger = logger.createChild({
|
|
69
|
+
context: { scope: "request" },
|
|
70
|
+
});
|
|
71
|
+
requestLogger.info("Incoming request");
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### JSON Logging
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { Logger, ConsoleTransport } from "zario";
|
|
78
|
+
|
|
79
|
+
const jsonLogger = new Logger({
|
|
80
|
+
json: true,
|
|
81
|
+
transports: [new ConsoleTransport()],
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### File Transport
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { Logger, FileTransport } from "zario";
|
|
89
|
+
|
|
90
|
+
const logger = new Logger({
|
|
91
|
+
transports: [
|
|
92
|
+
new FileTransport({
|
|
93
|
+
path: "./logs/app.log",
|
|
94
|
+
maxSize: 10 * 1024 * 1024,
|
|
95
|
+
maxFiles: 5,
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Lean Import
|
|
102
|
+
|
|
103
|
+
If you only need the core logger:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Logger } from "zario/logger";
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 📖 Documentation
|
|
110
|
+
|
|
111
|
+
| Section | Description |
|
|
112
|
+
|---|---|
|
|
113
|
+
| [Configuration](./docs/configuration.md) | Logger options, custom levels, and colors |
|
|
114
|
+
| [API Reference](./docs/api-reference.md) | Logger class and utilities |
|
|
115
|
+
| [Transports](./docs/transports.md) | Console, File, HTTP, CircuitBreaker, DeadLetterQueue |
|
|
116
|
+
| [Advanced Usage](./docs/advanced-usage.md) | Filters, enrichers, aggregators, async mode |
|
|
117
|
+
| [Log Formats](./docs/log-formats.md) | Text and JSON output spec |
|
|
118
|
+
| [Benchmarks](./docs/benchmarks.md) | Performance comparison with other libraries |
|
|
119
|
+
| [Roadmap](./docs/roadmap.md) | Future plans |
|
|
120
|
+
|
|
121
|
+
## 🤝 Contributing
|
|
122
|
+
|
|
123
|
+
Bug reports, feature requests, and pull requests welcome. See [Contributing Guide](./CONTRIBUTING.md).
|
|
124
|
+
|
|
125
|
+
## 📄 License
|
|
126
|
+
|
|
127
|
+
[MIT License](./LICENSE)
|
|
128
|
+
|
|
129
|
+
<br/>
|
|
130
|
+
|
|
131
|
+
<div align="center">
|
|
132
|
+
|
|
133
|
+
⭐ Star this repository if you find it useful
|
|
134
|
+
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<br/>
|
|
138
|
+
|
|
139
|
+
[⬆ Back to Top](#top)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/aggregation/LogAggregator.ts
|
|
21
|
+
var LogAggregator_exports = {};
|
|
22
|
+
__export(LogAggregator_exports, {
|
|
23
|
+
BatchAggregator: () => BatchAggregator,
|
|
24
|
+
CompositeAggregator: () => CompositeAggregator,
|
|
25
|
+
TimeBasedAggregator: () => TimeBasedAggregator
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(LogAggregator_exports);
|
|
28
|
+
var BatchAggregator = class {
|
|
29
|
+
constructor(maxSize = 100, flushCallback, maxQueueSize = 1e4) {
|
|
30
|
+
this.logs = [];
|
|
31
|
+
this.pendingFlush = null;
|
|
32
|
+
this.maxSize = maxSize;
|
|
33
|
+
this.maxQueueSize = maxQueueSize;
|
|
34
|
+
this.flushCallback = flushCallback;
|
|
35
|
+
}
|
|
36
|
+
aggregate(logData, formatter) {
|
|
37
|
+
if (this.logs.length >= this.maxQueueSize) {
|
|
38
|
+
this.logs.shift();
|
|
39
|
+
}
|
|
40
|
+
this.logs.push({ logData, formatter });
|
|
41
|
+
if (this.logs.length >= this.maxSize && !this.pendingFlush) {
|
|
42
|
+
const result = this.flush();
|
|
43
|
+
if (result instanceof Promise) {
|
|
44
|
+
this.pendingFlush = result.finally(() => {
|
|
45
|
+
this.pendingFlush = null;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
flush() {
|
|
51
|
+
if (this.pendingFlush) {
|
|
52
|
+
return this.pendingFlush;
|
|
53
|
+
}
|
|
54
|
+
if (this.logs.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const logsToFlush = this.logs;
|
|
58
|
+
this.logs = [];
|
|
59
|
+
try {
|
|
60
|
+
const callbackResult = this.flushCallback(logsToFlush);
|
|
61
|
+
if (callbackResult instanceof Promise) {
|
|
62
|
+
return callbackResult.catch((error) => {
|
|
63
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var TimeBasedAggregator = class {
|
|
74
|
+
constructor(flushInterval, flushCallback, maxQueueSize = 1e4) {
|
|
75
|
+
this.logs = [];
|
|
76
|
+
this.timer = null;
|
|
77
|
+
this.flushInterval = flushInterval;
|
|
78
|
+
this.maxQueueSize = maxQueueSize;
|
|
79
|
+
this.flushCallback = flushCallback;
|
|
80
|
+
}
|
|
81
|
+
aggregate(logData, formatter) {
|
|
82
|
+
if (this.logs.length >= this.maxQueueSize) {
|
|
83
|
+
this.logs.shift();
|
|
84
|
+
}
|
|
85
|
+
this.logs.push({ logData, formatter });
|
|
86
|
+
if (!this.timer) {
|
|
87
|
+
this.timer = setTimeout(() => {
|
|
88
|
+
const result = this.flush();
|
|
89
|
+
if (result instanceof Promise) {
|
|
90
|
+
result.catch((error) => {
|
|
91
|
+
console.error(
|
|
92
|
+
"Error in TimeBasedAggregator flush callback:",
|
|
93
|
+
error
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, this.flushInterval);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
flush() {
|
|
101
|
+
if (this.logs.length > 0) {
|
|
102
|
+
if (this.timer) {
|
|
103
|
+
clearTimeout(this.timer);
|
|
104
|
+
this.timer = null;
|
|
105
|
+
}
|
|
106
|
+
const logsToFlush = this.logs;
|
|
107
|
+
this.logs = [];
|
|
108
|
+
try {
|
|
109
|
+
const callbackResult = this.flushCallback(logsToFlush);
|
|
110
|
+
if (callbackResult instanceof Promise) {
|
|
111
|
+
return callbackResult.catch((error) => {
|
|
112
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//Stop aggregator and cancel any pending timer without flushing
|
|
123
|
+
stop() {
|
|
124
|
+
if (this.timer) {
|
|
125
|
+
clearTimeout(this.timer);
|
|
126
|
+
this.timer = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var CompositeAggregator = class {
|
|
131
|
+
constructor(aggregators) {
|
|
132
|
+
this.aggregators = aggregators;
|
|
133
|
+
}
|
|
134
|
+
aggregate(logData, formatter) {
|
|
135
|
+
for (const aggregator of this.aggregators) {
|
|
136
|
+
aggregator.aggregate(logData, formatter);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
flush() {
|
|
140
|
+
const results = [];
|
|
141
|
+
for (const aggregator of this.aggregators) {
|
|
142
|
+
const result = aggregator.flush();
|
|
143
|
+
if (result) {
|
|
144
|
+
results.push(result);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (results.some((r) => r instanceof Promise)) {
|
|
148
|
+
const promiseResults = results.filter(
|
|
149
|
+
(r) => r instanceof Promise
|
|
150
|
+
);
|
|
151
|
+
return Promise.all(promiseResults).then(() => {
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
+
0 && (module.exports = {
|
|
158
|
+
BatchAggregator,
|
|
159
|
+
CompositeAggregator,
|
|
160
|
+
TimeBasedAggregator
|
|
161
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { e as BatchAggregator, f as CompositeAggregator, k as LogAggregator, t as TimeBasedAggregator } from '../index-BRrRLU1p.cjs';
|
|
2
|
+
import '../core/LogLevel.cjs';
|
|
3
|
+
import 'events';
|
|
4
|
+
import '../utils/Timer.cjs';
|
|
5
|
+
import '../utils/Redactor.cjs';
|
|
6
|
+
import '../types/OpenTelemetryTypes.cjs';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { e as BatchAggregator, f as CompositeAggregator, k as LogAggregator, t as TimeBasedAggregator } from '../index-BQ3Wnw2M.js';
|
|
2
|
+
import '../core/LogLevel.js';
|
|
3
|
+
import 'events';
|
|
4
|
+
import '../utils/Timer.js';
|
|
5
|
+
import '../utils/Redactor.js';
|
|
6
|
+
import '../types/OpenTelemetryTypes.js';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/aggregation/LogAggregator.ts
|
|
2
|
+
var BatchAggregator = class {
|
|
3
|
+
constructor(maxSize = 100, flushCallback, maxQueueSize = 1e4) {
|
|
4
|
+
this.logs = [];
|
|
5
|
+
this.pendingFlush = null;
|
|
6
|
+
this.maxSize = maxSize;
|
|
7
|
+
this.maxQueueSize = maxQueueSize;
|
|
8
|
+
this.flushCallback = flushCallback;
|
|
9
|
+
}
|
|
10
|
+
aggregate(logData, formatter) {
|
|
11
|
+
if (this.logs.length >= this.maxQueueSize) {
|
|
12
|
+
this.logs.shift();
|
|
13
|
+
}
|
|
14
|
+
this.logs.push({ logData, formatter });
|
|
15
|
+
if (this.logs.length >= this.maxSize && !this.pendingFlush) {
|
|
16
|
+
const result = this.flush();
|
|
17
|
+
if (result instanceof Promise) {
|
|
18
|
+
this.pendingFlush = result.finally(() => {
|
|
19
|
+
this.pendingFlush = null;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
flush() {
|
|
25
|
+
if (this.pendingFlush) {
|
|
26
|
+
return this.pendingFlush;
|
|
27
|
+
}
|
|
28
|
+
if (this.logs.length === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const logsToFlush = this.logs;
|
|
32
|
+
this.logs = [];
|
|
33
|
+
try {
|
|
34
|
+
const callbackResult = this.flushCallback(logsToFlush);
|
|
35
|
+
if (callbackResult instanceof Promise) {
|
|
36
|
+
return callbackResult.catch((error) => {
|
|
37
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var TimeBasedAggregator = class {
|
|
48
|
+
constructor(flushInterval, flushCallback, maxQueueSize = 1e4) {
|
|
49
|
+
this.logs = [];
|
|
50
|
+
this.timer = null;
|
|
51
|
+
this.flushInterval = flushInterval;
|
|
52
|
+
this.maxQueueSize = maxQueueSize;
|
|
53
|
+
this.flushCallback = flushCallback;
|
|
54
|
+
}
|
|
55
|
+
aggregate(logData, formatter) {
|
|
56
|
+
if (this.logs.length >= this.maxQueueSize) {
|
|
57
|
+
this.logs.shift();
|
|
58
|
+
}
|
|
59
|
+
this.logs.push({ logData, formatter });
|
|
60
|
+
if (!this.timer) {
|
|
61
|
+
this.timer = setTimeout(() => {
|
|
62
|
+
const result = this.flush();
|
|
63
|
+
if (result instanceof Promise) {
|
|
64
|
+
result.catch((error) => {
|
|
65
|
+
console.error(
|
|
66
|
+
"Error in TimeBasedAggregator flush callback:",
|
|
67
|
+
error
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, this.flushInterval);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
flush() {
|
|
75
|
+
if (this.logs.length > 0) {
|
|
76
|
+
if (this.timer) {
|
|
77
|
+
clearTimeout(this.timer);
|
|
78
|
+
this.timer = null;
|
|
79
|
+
}
|
|
80
|
+
const logsToFlush = this.logs;
|
|
81
|
+
this.logs = [];
|
|
82
|
+
try {
|
|
83
|
+
const callbackResult = this.flushCallback(logsToFlush);
|
|
84
|
+
if (callbackResult instanceof Promise) {
|
|
85
|
+
return callbackResult.catch((error) => {
|
|
86
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
87
|
+
throw error;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
this.logs = logsToFlush.concat(this.logs);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//Stop aggregator and cancel any pending timer without flushing
|
|
97
|
+
stop() {
|
|
98
|
+
if (this.timer) {
|
|
99
|
+
clearTimeout(this.timer);
|
|
100
|
+
this.timer = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var CompositeAggregator = class {
|
|
105
|
+
constructor(aggregators) {
|
|
106
|
+
this.aggregators = aggregators;
|
|
107
|
+
}
|
|
108
|
+
aggregate(logData, formatter) {
|
|
109
|
+
for (const aggregator of this.aggregators) {
|
|
110
|
+
aggregator.aggregate(logData, formatter);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
flush() {
|
|
114
|
+
const results = [];
|
|
115
|
+
for (const aggregator of this.aggregators) {
|
|
116
|
+
const result = aggregator.flush();
|
|
117
|
+
if (result) {
|
|
118
|
+
results.push(result);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (results.some((r) => r instanceof Promise)) {
|
|
122
|
+
const promiseResults = results.filter(
|
|
123
|
+
(r) => r instanceof Promise
|
|
124
|
+
);
|
|
125
|
+
return Promise.all(promiseResults).then(() => {
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export {
|
|
131
|
+
BatchAggregator,
|
|
132
|
+
CompositeAggregator,
|
|
133
|
+
TimeBasedAggregator
|
|
134
|
+
};
|