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.
Files changed (206) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +139 -102
  3. package/dist/aggregation/LogAggregator.cjs +161 -0
  4. package/dist/aggregation/LogAggregator.d.cts +6 -0
  5. package/dist/aggregation/LogAggregator.d.ts +6 -0
  6. package/dist/aggregation/LogAggregator.js +134 -0
  7. package/dist/aggregation/index.cjs +163 -0
  8. package/dist/aggregation/index.d.cts +6 -0
  9. package/dist/aggregation/index.d.ts +6 -0
  10. package/dist/aggregation/index.js +134 -0
  11. package/dist/context/RequestContext.cjs +68 -0
  12. package/dist/context/RequestContext.d.cts +16 -0
  13. package/dist/context/RequestContext.d.ts +16 -0
  14. package/dist/context/RequestContext.js +43 -0
  15. package/dist/context/index.cjs +70 -0
  16. package/dist/context/index.d.cts +2 -0
  17. package/dist/context/index.d.ts +2 -0
  18. package/dist/context/index.js +43 -0
  19. package/dist/core/CustomLogLevel.cjs +18 -0
  20. package/dist/core/CustomLogLevel.d.cts +9 -0
  21. package/dist/core/CustomLogLevel.d.ts +9 -0
  22. package/dist/core/CustomLogLevel.js +0 -0
  23. package/dist/core/Formatter.cjs +231 -0
  24. package/dist/core/Formatter.d.cts +6 -0
  25. package/dist/core/Formatter.d.ts +6 -0
  26. package/dist/core/Formatter.js +204 -0
  27. package/dist/core/LogLevel.cjs +18 -0
  28. package/dist/core/LogLevel.d.cts +3 -0
  29. package/dist/core/LogLevel.d.ts +3 -0
  30. package/dist/core/LogLevel.js +0 -0
  31. package/dist/core/Logger.cjs +796 -0
  32. package/dist/core/Logger.d.cts +6 -0
  33. package/dist/core/Logger.d.ts +6 -0
  34. package/dist/core/Logger.js +769 -0
  35. package/dist/filters/Filter.cjs +122 -0
  36. package/dist/filters/Filter.d.cts +6 -0
  37. package/dist/filters/Filter.d.ts +6 -0
  38. package/dist/filters/Filter.js +90 -0
  39. package/dist/filters/index.cjs +124 -0
  40. package/dist/filters/index.d.cts +6 -0
  41. package/dist/filters/index.d.ts +6 -0
  42. package/dist/filters/index.js +90 -0
  43. package/dist/index-BQ3Wnw2M.d.ts +424 -0
  44. package/dist/index-BRrRLU1p.d.cts +424 -0
  45. package/dist/index.cjs +2233 -0
  46. package/dist/index.d.cts +21 -0
  47. package/dist/index.d.ts +19 -0
  48. package/dist/index.js +2175 -0
  49. package/dist/logger.cjs +800 -0
  50. package/dist/logger.d.cts +13 -0
  51. package/dist/logger.d.ts +11 -0
  52. package/dist/logger.js +773 -0
  53. package/dist/otel/OTelContextProvider.cjs +117 -0
  54. package/dist/otel/OTelContextProvider.d.cts +18 -0
  55. package/dist/otel/OTelContextProvider.d.ts +18 -0
  56. package/dist/otel/OTelContextProvider.js +95 -0
  57. package/dist/otel/index.cjs +119 -0
  58. package/dist/otel/index.d.cts +2 -0
  59. package/dist/otel/index.d.ts +2 -0
  60. package/dist/otel/index.js +95 -0
  61. package/dist/structured/StructuredExtensions.cjs +279 -0
  62. package/dist/structured/StructuredExtensions.d.cts +6 -0
  63. package/dist/structured/StructuredExtensions.d.ts +6 -0
  64. package/dist/structured/StructuredExtensions.js +250 -0
  65. package/dist/structured/index.cjs +281 -0
  66. package/dist/structured/index.d.cts +6 -0
  67. package/dist/structured/index.d.ts +6 -0
  68. package/dist/structured/index.js +250 -0
  69. package/dist/transports/CircuitBreakerTransport.cjs +203 -0
  70. package/dist/transports/CircuitBreakerTransport.d.cts +49 -0
  71. package/dist/{esm/transports → transports}/CircuitBreakerTransport.d.ts +13 -7
  72. package/dist/transports/CircuitBreakerTransport.js +178 -0
  73. package/dist/transports/ConsoleTransport.cjs +55 -0
  74. package/dist/transports/ConsoleTransport.d.cts +18 -0
  75. package/dist/transports/ConsoleTransport.d.ts +18 -0
  76. package/dist/transports/ConsoleTransport.js +30 -0
  77. package/dist/transports/DeadLetterQueue.cjs +147 -0
  78. package/dist/transports/DeadLetterQueue.d.cts +41 -0
  79. package/dist/{esm/transports → transports}/DeadLetterQueue.d.ts +15 -8
  80. package/dist/transports/DeadLetterQueue.js +112 -0
  81. package/dist/transports/FileTransport.cjs +280 -0
  82. package/dist/transports/FileTransport.d.cts +6 -0
  83. package/dist/transports/FileTransport.d.ts +6 -0
  84. package/dist/transports/FileTransport.js +245 -0
  85. package/dist/transports/FilterableTransport.cjs +57 -0
  86. package/dist/transports/FilterableTransport.d.cts +19 -0
  87. package/dist/transports/FilterableTransport.d.ts +19 -0
  88. package/dist/transports/FilterableTransport.js +32 -0
  89. package/dist/transports/HttpTransport.cjs +164 -0
  90. package/dist/transports/HttpTransport.d.cts +36 -0
  91. package/dist/transports/HttpTransport.d.ts +36 -0
  92. package/dist/transports/HttpTransport.js +129 -0
  93. package/dist/transports/RetryTransport.cjs +243 -0
  94. package/dist/transports/RetryTransport.d.cts +6 -0
  95. package/dist/transports/RetryTransport.d.ts +6 -0
  96. package/dist/transports/RetryTransport.js +217 -0
  97. package/dist/transports/Transport.cjs +18 -0
  98. package/dist/transports/Transport.d.cts +6 -0
  99. package/dist/transports/Transport.d.ts +6 -0
  100. package/dist/transports/Transport.js +0 -0
  101. package/dist/transports/index.cjs +981 -0
  102. package/dist/transports/index.d.cts +11 -0
  103. package/dist/transports/index.d.ts +11 -0
  104. package/dist/transports/index.js +937 -0
  105. package/dist/types/OpenTelemetryTypes.cjs +18 -0
  106. package/dist/types/OpenTelemetryTypes.d.cts +60 -0
  107. package/dist/types/OpenTelemetryTypes.d.ts +60 -0
  108. package/dist/types/OpenTelemetryTypes.js +0 -0
  109. package/dist/types/TypeInterfaces.cjs +18 -0
  110. package/dist/types/TypeInterfaces.d.cts +9 -0
  111. package/dist/types/TypeInterfaces.d.ts +9 -0
  112. package/dist/types/TypeInterfaces.js +0 -0
  113. package/dist/types/index.d.cjs +18 -0
  114. package/dist/types/index.d.d.cts +6 -0
  115. package/dist/types/index.d.d.ts +6 -0
  116. package/dist/types/index.d.js +0 -0
  117. package/dist/utils/BufferedWriteStream.cjs +160 -0
  118. package/dist/utils/BufferedWriteStream.d.cts +27 -0
  119. package/dist/utils/BufferedWriteStream.d.ts +27 -0
  120. package/dist/utils/BufferedWriteStream.js +125 -0
  121. package/dist/utils/ColorUtil.cjs +79 -0
  122. package/dist/utils/ColorUtil.d.cts +9 -0
  123. package/dist/utils/ColorUtil.d.ts +9 -0
  124. package/dist/utils/ColorUtil.js +54 -0
  125. package/dist/utils/Redactor.cjs +73 -0
  126. package/dist/utils/Redactor.d.cts +42 -0
  127. package/dist/utils/Redactor.d.ts +42 -0
  128. package/dist/utils/Redactor.js +48 -0
  129. package/dist/utils/TimeUtil.cjs +66 -0
  130. package/dist/utils/TimeUtil.d.cts +5 -0
  131. package/dist/utils/TimeUtil.d.ts +5 -0
  132. package/dist/utils/TimeUtil.js +41 -0
  133. package/dist/utils/Timer.cjs +46 -0
  134. package/dist/utils/Timer.d.cts +10 -0
  135. package/dist/utils/Timer.d.ts +10 -0
  136. package/dist/utils/Timer.js +21 -0
  137. package/dist/utils/index.cjs +278 -0
  138. package/dist/utils/index.d.cts +4 -0
  139. package/dist/utils/index.d.ts +4 -0
  140. package/dist/utils/index.js +238 -0
  141. package/package.json +93 -87
  142. package/dist/cjs/aggregation/LogAggregator.js +0 -139
  143. package/dist/cjs/aggregation/index.js +0 -17
  144. package/dist/cjs/core/CustomLogLevel.js +0 -2
  145. package/dist/cjs/core/Formatter.js +0 -74
  146. package/dist/cjs/core/LogLevel.js +0 -2
  147. package/dist/cjs/core/Logger.js +0 -355
  148. package/dist/cjs/filters/Filter.js +0 -90
  149. package/dist/cjs/filters/index.js +0 -17
  150. package/dist/cjs/index.js +0 -41
  151. package/dist/cjs/package.json +0 -1
  152. package/dist/cjs/structured/StructuredExtensions.js +0 -112
  153. package/dist/cjs/structured/index.js +0 -17
  154. package/dist/cjs/transports/CircuitBreakerTransport.js +0 -171
  155. package/dist/cjs/transports/ConsoleTransport.js +0 -39
  156. package/dist/cjs/transports/DeadLetterQueue.js +0 -129
  157. package/dist/cjs/transports/FileTransport.js +0 -331
  158. package/dist/cjs/transports/FilterableTransport.js +0 -39
  159. package/dist/cjs/transports/HttpTransport.js +0 -162
  160. package/dist/cjs/transports/RetryTransport.js +0 -199
  161. package/dist/cjs/transports/Transport.js +0 -2
  162. package/dist/cjs/transports/index.js +0 -24
  163. package/dist/cjs/types/TypeInterfaces.js +0 -2
  164. package/dist/cjs/utils/index.js +0 -78
  165. package/dist/esm/aggregation/LogAggregator.d.ts +0 -39
  166. package/dist/esm/aggregation/LogAggregator.js +0 -133
  167. package/dist/esm/aggregation/index.d.ts +0 -1
  168. package/dist/esm/aggregation/index.js +0 -1
  169. package/dist/esm/core/CustomLogLevel.d.ts +0 -6
  170. package/dist/esm/core/CustomLogLevel.js +0 -1
  171. package/dist/esm/core/Formatter.d.ts +0 -29
  172. package/dist/esm/core/Formatter.js +0 -70
  173. package/dist/esm/core/LogLevel.d.ts +0 -1
  174. package/dist/esm/core/LogLevel.js +0 -1
  175. package/dist/esm/core/Logger.d.ts +0 -109
  176. package/dist/esm/core/Logger.js +0 -351
  177. package/dist/esm/filters/Filter.d.ts +0 -49
  178. package/dist/esm/filters/Filter.js +0 -79
  179. package/dist/esm/filters/index.d.ts +0 -1
  180. package/dist/esm/filters/index.js +0 -1
  181. package/dist/esm/index.d.ts +0 -12
  182. package/dist/esm/index.js +0 -25
  183. package/dist/esm/structured/StructuredExtensions.d.ts +0 -31
  184. package/dist/esm/structured/StructuredExtensions.js +0 -74
  185. package/dist/esm/structured/index.d.ts +0 -1
  186. package/dist/esm/structured/index.js +0 -1
  187. package/dist/esm/transports/CircuitBreakerTransport.js +0 -167
  188. package/dist/esm/transports/ConsoleTransport.d.ts +0 -12
  189. package/dist/esm/transports/ConsoleTransport.js +0 -35
  190. package/dist/esm/transports/DeadLetterQueue.js +0 -92
  191. package/dist/esm/transports/FileTransport.d.ts +0 -45
  192. package/dist/esm/transports/FileTransport.js +0 -294
  193. package/dist/esm/transports/FilterableTransport.d.ts +0 -14
  194. package/dist/esm/transports/FilterableTransport.js +0 -35
  195. package/dist/esm/transports/HttpTransport.d.ts +0 -26
  196. package/dist/esm/transports/HttpTransport.js +0 -125
  197. package/dist/esm/transports/RetryTransport.d.ts +0 -67
  198. package/dist/esm/transports/RetryTransport.js +0 -195
  199. package/dist/esm/transports/Transport.d.ts +0 -7
  200. package/dist/esm/transports/Transport.js +0 -1
  201. package/dist/esm/transports/index.d.ts +0 -8
  202. package/dist/esm/transports/index.js +0 -8
  203. package/dist/esm/types/TypeInterfaces.d.ts +0 -7
  204. package/dist/esm/types/TypeInterfaces.js +0 -1
  205. package/dist/esm/utils/index.d.ts +0 -15
  206. 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
- ### A Minimal Logging Solution for TypeScript
8
-
9
- [![npm version](https://img.shields.io/npm/v/zario?style=for-the-badge&logo=npm&color=CB3837)](https://www.npmjs.com/package/zario)
10
- [![license](https://img.shields.io/npm/l/zario?style=for-the-badge&color=green)](./LICENSE)
11
- [![downloads](https://img.shields.io/npm/dt/zario?style=for-the-badge&logo=npm&color=orange)](https://www.npmjs.com/package/zario)
12
- [![bundle size](https://img.shields.io/bundlephobia/minzip/zario?style=for-the-badge&logo=webpack&color=purple)](https://bundlephobia.com/package/zario)
13
- ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Dev-Dami/zario?label=build)](https://github.com/Dev-Dami/zario/actions)
14
-
15
-
16
-
17
- <br/>
18
-
19
- **Fast** • **Lightweight** • **Zero Dependencies** • **TypeScript Native**
20
-
21
- <br/>
22
-
23
- [📖 Documentation](#-documentation) · [⚡ Quick Start](#-quick-start) · [✨ Features](#-features) · [🤝 Contributing](#-contributing)
24
-
25
- <br/>
26
-
27
- ![separator](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)
28
-
29
- </div>
30
-
31
- <br/>
32
-
33
- ## Features
34
-
35
- - **Lightweight** — minimal footprint, fast execution
36
- - **Simple API** — intuitive methods like `info()`, `warn()`, `error()`
37
- - **Flexible formatting** — plain text or structured JSON
38
- - **Multiple transports** — Console, File (streaming rotation), HTTP (async retry), CircuitBreaker, and DeadLetterQueue
39
- - **Child loggers** — scoped logging for modules or requests
40
- - **Async mode** — non-blocking writes for high-performance applications
41
- - **Memory safe** — bounded queues and memory-efficient streaming
42
- - **Customizable** — custom log levels, colors, and filtering
43
-
44
- ## 📦 Installation
45
-
46
- ```bash
47
- npm install zario
48
- ```
49
-
50
- ## 🚀 Quick Start
51
-
52
- ```typescript
53
- import { Logger, ConsoleTransport } from "zario";
54
-
55
- const logger = new Logger({
56
- level: "info",
57
- colorize: true,
58
- transports: [new ConsoleTransport()],
59
- prefix: "[MyApp]",
60
- });
61
-
62
- logger.info("🚀 Server started on port 3000");
63
- logger.warn("⚠️ High memory usage detected");
64
- logger.error("❌ Database connection failed", { code: 500 });
65
- ```
66
-
67
- ## 📖 Documentation
68
-
69
- Documentation:
70
-
71
- | Section | Description |
72
- | --------------------------------------------------- | ----------------------------------------------------------------------------- |
73
- | [📘 **Introduction**](./docs/introduction.md) | Philosophy, core features, and common use cases. |
74
- | [🚀 **Getting Started**](./docs/getting-started.md) | Detailed installation and environment auto-configuration. |
75
- | [⚙️ **Configuration**](./docs/configuration.md) | Full reference for all logger options, custom levels, and colors. |
76
- | [📖 **API Reference**](./docs/api-reference.md) | Detailed API documentation for the Logger class and utilities. |
77
- | [📁 **Transports**](./docs/transports.md) | Guide to Console, File, HTTP, CircuitBreaker, and DeadLetterQueue transports. |
78
- | [🧩 **Advanced Usage**](./docs/advanced-usage.md) | Filters, Enrichers (Structured Logging), and Aggregators. |
79
- | [📊 **Log Formats**](./docs/log-formats.md) | Specification for Text and JSON output formats. |
80
- | [🗺️ **Roadmap**](./docs/roadmap.md) | Future plans and upcoming features. |
81
-
82
- ## 🤝 Contributing
83
-
84
- We welcome contributions! Whether it's bug reports, feature requests, or code contributions. Please see our [Contributing Guide](./CONTRIBUTING.md) for more details.
85
-
86
- ## 📄 License
87
-
88
- This project is licensed under the **MIT License** - see the [LICENSE](./LICENSE) file for full details.
89
-
90
- <br/>
91
-
92
- <div align="center">
93
-
94
- ### Developed for developers
95
-
96
- ⭐ Star this repository to show your support
97
-
98
- </div>
99
-
100
- <br/>
101
-
102
- [⬆ Back to Top](#top)
1
+ <div align="center">
2
+
3
+ <a id="top"></a>
4
+
5
+ # 📝 Zario
6
+
7
+ ### Fast and simple logging library for TypeScript
8
+
9
+ [![npm version](https://img.shields.io/npm/v/zario?style=for-the-badge&logo=npm&color=CB3837)](https://www.npmjs.com/package/zario)
10
+ [![license](https://img.shields.io/npm/l/zario?style=for-the-badge&color=green)](./LICENSE)
11
+ [![downloads](https://img.shields.io/npm/dt/zario?style=for-the-badge&logo=npm&color=orange)](https://www.npmjs.com/package/zario)
12
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/zario?style=for-the-badge&logo=webpack&color=purple)](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
+ ![separator](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)
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
+ };