@mastra/loggers 0.0.1-alpha.1 → 0.0.1-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -0
- package/README.md +146 -0
- package/dist/file/index.d.ts +4 -2
- package/dist/file/index.js +49 -0
- package/dist/upstash/index.d.ts +5 -3
- package/dist/upstash/index.js +111 -0
- package/package.json +20 -14
- package/src/index.ts +0 -2
- package/dist/file/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/loggers.cjs.development.js +0 -665
- package/dist/loggers.cjs.development.js.map +0 -1
- package/dist/loggers.cjs.production.min.js +0 -2
- package/dist/loggers.cjs.production.min.js.map +0 -1
- package/dist/loggers.esm.js +0 -660
- package/dist/loggers.esm.js.map +0 -1
- package/dist/upstash/index.d.ts.map +0 -1
package/dist/loggers.esm.js
DELETED
|
@@ -1,660 +0,0 @@
|
|
|
1
|
-
import { LoggerTransport } from '@mastra/core';
|
|
2
|
-
import { existsSync, createWriteStream, readFileSync } from 'fs';
|
|
3
|
-
|
|
4
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
5
|
-
try {
|
|
6
|
-
var i = n[a](c),
|
|
7
|
-
u = i.value;
|
|
8
|
-
} catch (n) {
|
|
9
|
-
return void e(n);
|
|
10
|
-
}
|
|
11
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
12
|
-
}
|
|
13
|
-
function _asyncToGenerator(n) {
|
|
14
|
-
return function () {
|
|
15
|
-
var t = this,
|
|
16
|
-
e = arguments;
|
|
17
|
-
return new Promise(function (r, o) {
|
|
18
|
-
var a = n.apply(t, e);
|
|
19
|
-
function _next(n) {
|
|
20
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
21
|
-
}
|
|
22
|
-
function _throw(n) {
|
|
23
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
24
|
-
}
|
|
25
|
-
_next(void 0);
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function _inheritsLoose(t, o) {
|
|
30
|
-
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
31
|
-
}
|
|
32
|
-
function _regeneratorRuntime() {
|
|
33
|
-
_regeneratorRuntime = function () {
|
|
34
|
-
return e;
|
|
35
|
-
};
|
|
36
|
-
var t,
|
|
37
|
-
e = {},
|
|
38
|
-
r = Object.prototype,
|
|
39
|
-
n = r.hasOwnProperty,
|
|
40
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
41
|
-
t[e] = r.value;
|
|
42
|
-
},
|
|
43
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
44
|
-
a = i.iterator || "@@iterator",
|
|
45
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
46
|
-
u = i.toStringTag || "@@toStringTag";
|
|
47
|
-
function define(t, e, r) {
|
|
48
|
-
return Object.defineProperty(t, e, {
|
|
49
|
-
value: r,
|
|
50
|
-
enumerable: !0,
|
|
51
|
-
configurable: !0,
|
|
52
|
-
writable: !0
|
|
53
|
-
}), t[e];
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
define({}, "");
|
|
57
|
-
} catch (t) {
|
|
58
|
-
define = function (t, e, r) {
|
|
59
|
-
return t[e] = r;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function wrap(t, e, r, n) {
|
|
63
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
64
|
-
a = Object.create(i.prototype),
|
|
65
|
-
c = new Context(n || []);
|
|
66
|
-
return o(a, "_invoke", {
|
|
67
|
-
value: makeInvokeMethod(t, r, c)
|
|
68
|
-
}), a;
|
|
69
|
-
}
|
|
70
|
-
function tryCatch(t, e, r) {
|
|
71
|
-
try {
|
|
72
|
-
return {
|
|
73
|
-
type: "normal",
|
|
74
|
-
arg: t.call(e, r)
|
|
75
|
-
};
|
|
76
|
-
} catch (t) {
|
|
77
|
-
return {
|
|
78
|
-
type: "throw",
|
|
79
|
-
arg: t
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
e.wrap = wrap;
|
|
84
|
-
var h = "suspendedStart",
|
|
85
|
-
l = "suspendedYield",
|
|
86
|
-
f = "executing",
|
|
87
|
-
s = "completed",
|
|
88
|
-
y = {};
|
|
89
|
-
function Generator() {}
|
|
90
|
-
function GeneratorFunction() {}
|
|
91
|
-
function GeneratorFunctionPrototype() {}
|
|
92
|
-
var p = {};
|
|
93
|
-
define(p, a, function () {
|
|
94
|
-
return this;
|
|
95
|
-
});
|
|
96
|
-
var d = Object.getPrototypeOf,
|
|
97
|
-
v = d && d(d(values([])));
|
|
98
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
99
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
100
|
-
function defineIteratorMethods(t) {
|
|
101
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
102
|
-
define(t, e, function (t) {
|
|
103
|
-
return this._invoke(e, t);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function AsyncIterator(t, e) {
|
|
108
|
-
function invoke(r, o, i, a) {
|
|
109
|
-
var c = tryCatch(t[r], t, o);
|
|
110
|
-
if ("throw" !== c.type) {
|
|
111
|
-
var u = c.arg,
|
|
112
|
-
h = u.value;
|
|
113
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
114
|
-
invoke("next", t, i, a);
|
|
115
|
-
}, function (t) {
|
|
116
|
-
invoke("throw", t, i, a);
|
|
117
|
-
}) : e.resolve(h).then(function (t) {
|
|
118
|
-
u.value = t, i(u);
|
|
119
|
-
}, function (t) {
|
|
120
|
-
return invoke("throw", t, i, a);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
a(c.arg);
|
|
124
|
-
}
|
|
125
|
-
var r;
|
|
126
|
-
o(this, "_invoke", {
|
|
127
|
-
value: function (t, n) {
|
|
128
|
-
function callInvokeWithMethodAndArg() {
|
|
129
|
-
return new e(function (e, r) {
|
|
130
|
-
invoke(t, n, e, r);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
function makeInvokeMethod(e, r, n) {
|
|
138
|
-
var o = h;
|
|
139
|
-
return function (i, a) {
|
|
140
|
-
if (o === f) throw Error("Generator is already running");
|
|
141
|
-
if (o === s) {
|
|
142
|
-
if ("throw" === i) throw a;
|
|
143
|
-
return {
|
|
144
|
-
value: t,
|
|
145
|
-
done: !0
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
for (n.method = i, n.arg = a;;) {
|
|
149
|
-
var c = n.delegate;
|
|
150
|
-
if (c) {
|
|
151
|
-
var u = maybeInvokeDelegate(c, n);
|
|
152
|
-
if (u) {
|
|
153
|
-
if (u === y) continue;
|
|
154
|
-
return u;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
158
|
-
if (o === h) throw o = s, n.arg;
|
|
159
|
-
n.dispatchException(n.arg);
|
|
160
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
161
|
-
o = f;
|
|
162
|
-
var p = tryCatch(e, r, n);
|
|
163
|
-
if ("normal" === p.type) {
|
|
164
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
165
|
-
return {
|
|
166
|
-
value: p.arg,
|
|
167
|
-
done: n.done
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function maybeInvokeDelegate(e, r) {
|
|
175
|
-
var n = r.method,
|
|
176
|
-
o = e.iterator[n];
|
|
177
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
178
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
179
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
180
|
-
var a = i.arg;
|
|
181
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
182
|
-
}
|
|
183
|
-
function pushTryEntry(t) {
|
|
184
|
-
var e = {
|
|
185
|
-
tryLoc: t[0]
|
|
186
|
-
};
|
|
187
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
188
|
-
}
|
|
189
|
-
function resetTryEntry(t) {
|
|
190
|
-
var e = t.completion || {};
|
|
191
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
192
|
-
}
|
|
193
|
-
function Context(t) {
|
|
194
|
-
this.tryEntries = [{
|
|
195
|
-
tryLoc: "root"
|
|
196
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
197
|
-
}
|
|
198
|
-
function values(e) {
|
|
199
|
-
if (e || "" === e) {
|
|
200
|
-
var r = e[a];
|
|
201
|
-
if (r) return r.call(e);
|
|
202
|
-
if ("function" == typeof e.next) return e;
|
|
203
|
-
if (!isNaN(e.length)) {
|
|
204
|
-
var o = -1,
|
|
205
|
-
i = function next() {
|
|
206
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
207
|
-
return next.value = t, next.done = !0, next;
|
|
208
|
-
};
|
|
209
|
-
return i.next = i;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
213
|
-
}
|
|
214
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
215
|
-
value: GeneratorFunctionPrototype,
|
|
216
|
-
configurable: !0
|
|
217
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
218
|
-
value: GeneratorFunction,
|
|
219
|
-
configurable: !0
|
|
220
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
221
|
-
var e = "function" == typeof t && t.constructor;
|
|
222
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
223
|
-
}, e.mark = function (t) {
|
|
224
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
225
|
-
}, e.awrap = function (t) {
|
|
226
|
-
return {
|
|
227
|
-
__await: t
|
|
228
|
-
};
|
|
229
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
230
|
-
return this;
|
|
231
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
232
|
-
void 0 === i && (i = Promise);
|
|
233
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
234
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
235
|
-
return t.done ? t.value : a.next();
|
|
236
|
-
});
|
|
237
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
238
|
-
return this;
|
|
239
|
-
}), define(g, "toString", function () {
|
|
240
|
-
return "[object Generator]";
|
|
241
|
-
}), e.keys = function (t) {
|
|
242
|
-
var e = Object(t),
|
|
243
|
-
r = [];
|
|
244
|
-
for (var n in e) r.push(n);
|
|
245
|
-
return r.reverse(), function next() {
|
|
246
|
-
for (; r.length;) {
|
|
247
|
-
var t = r.pop();
|
|
248
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
249
|
-
}
|
|
250
|
-
return next.done = !0, next;
|
|
251
|
-
};
|
|
252
|
-
}, e.values = values, Context.prototype = {
|
|
253
|
-
constructor: Context,
|
|
254
|
-
reset: function (e) {
|
|
255
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
256
|
-
},
|
|
257
|
-
stop: function () {
|
|
258
|
-
this.done = !0;
|
|
259
|
-
var t = this.tryEntries[0].completion;
|
|
260
|
-
if ("throw" === t.type) throw t.arg;
|
|
261
|
-
return this.rval;
|
|
262
|
-
},
|
|
263
|
-
dispatchException: function (e) {
|
|
264
|
-
if (this.done) throw e;
|
|
265
|
-
var r = this;
|
|
266
|
-
function handle(n, o) {
|
|
267
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
268
|
-
}
|
|
269
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
270
|
-
var i = this.tryEntries[o],
|
|
271
|
-
a = i.completion;
|
|
272
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
273
|
-
if (i.tryLoc <= this.prev) {
|
|
274
|
-
var c = n.call(i, "catchLoc"),
|
|
275
|
-
u = n.call(i, "finallyLoc");
|
|
276
|
-
if (c && u) {
|
|
277
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
278
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
279
|
-
} else if (c) {
|
|
280
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
281
|
-
} else {
|
|
282
|
-
if (!u) throw Error("try statement without catch or finally");
|
|
283
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
abrupt: function (t, e) {
|
|
289
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
290
|
-
var o = this.tryEntries[r];
|
|
291
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
292
|
-
var i = o;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
297
|
-
var a = i ? i.completion : {};
|
|
298
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
299
|
-
},
|
|
300
|
-
complete: function (t, e) {
|
|
301
|
-
if ("throw" === t.type) throw t.arg;
|
|
302
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
303
|
-
},
|
|
304
|
-
finish: function (t) {
|
|
305
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
306
|
-
var r = this.tryEntries[e];
|
|
307
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
catch: function (t) {
|
|
311
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
312
|
-
var r = this.tryEntries[e];
|
|
313
|
-
if (r.tryLoc === t) {
|
|
314
|
-
var n = r.completion;
|
|
315
|
-
if ("throw" === n.type) {
|
|
316
|
-
var o = n.arg;
|
|
317
|
-
resetTryEntry(r);
|
|
318
|
-
}
|
|
319
|
-
return o;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
throw Error("illegal catch attempt");
|
|
323
|
-
},
|
|
324
|
-
delegateYield: function (e, r, n) {
|
|
325
|
-
return this.delegate = {
|
|
326
|
-
iterator: values(e),
|
|
327
|
-
resultName: r,
|
|
328
|
-
nextLoc: n
|
|
329
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
330
|
-
}
|
|
331
|
-
}, e;
|
|
332
|
-
}
|
|
333
|
-
function _setPrototypeOf(t, e) {
|
|
334
|
-
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
335
|
-
return t.__proto__ = e, t;
|
|
336
|
-
}, _setPrototypeOf(t, e);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
var FileTransport = /*#__PURE__*/function (_LoggerTransport) {
|
|
340
|
-
function FileTransport(_ref) {
|
|
341
|
-
var _this;
|
|
342
|
-
var path = _ref.path;
|
|
343
|
-
_this = _LoggerTransport.call(this, {
|
|
344
|
-
objectMode: true
|
|
345
|
-
}) || this;
|
|
346
|
-
_this.path = void 0;
|
|
347
|
-
_this.fileStream = void 0;
|
|
348
|
-
_this.path = path;
|
|
349
|
-
if (!existsSync(_this.path)) {
|
|
350
|
-
console.log(_this.path);
|
|
351
|
-
throw new Error('File path does not exist');
|
|
352
|
-
}
|
|
353
|
-
_this.fileStream = createWriteStream(_this.path, {
|
|
354
|
-
flags: 'a'
|
|
355
|
-
});
|
|
356
|
-
return _this;
|
|
357
|
-
}
|
|
358
|
-
_inheritsLoose(FileTransport, _LoggerTransport);
|
|
359
|
-
var _proto = FileTransport.prototype;
|
|
360
|
-
_proto._transform = function _transform(chunk, _encoding, callback) {
|
|
361
|
-
try {
|
|
362
|
-
this.fileStream.write(chunk);
|
|
363
|
-
} catch (error) {
|
|
364
|
-
console.error('Error parsing log entry:', error);
|
|
365
|
-
}
|
|
366
|
-
callback(null, chunk);
|
|
367
|
-
};
|
|
368
|
-
_proto._flush = function _flush(callback) {
|
|
369
|
-
// End the file stream when transform stream ends
|
|
370
|
-
this.fileStream.end(function () {
|
|
371
|
-
callback();
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
// Clean up resources
|
|
375
|
-
;
|
|
376
|
-
_proto._destroy = function _destroy(error, callback) {
|
|
377
|
-
if (this.fileStream) {
|
|
378
|
-
this.fileStream.destroy(error);
|
|
379
|
-
}
|
|
380
|
-
callback(error);
|
|
381
|
-
};
|
|
382
|
-
_proto.getLogs = /*#__PURE__*/function () {
|
|
383
|
-
var _getLogs = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
384
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
385
|
-
while (1) switch (_context.prev = _context.next) {
|
|
386
|
-
case 0:
|
|
387
|
-
return _context.abrupt("return", readFileSync(this.path, 'utf8').split('\n').filter(Boolean).map(function (log) {
|
|
388
|
-
return JSON.parse(log);
|
|
389
|
-
}));
|
|
390
|
-
case 1:
|
|
391
|
-
case "end":
|
|
392
|
-
return _context.stop();
|
|
393
|
-
}
|
|
394
|
-
}, _callee, this);
|
|
395
|
-
}));
|
|
396
|
-
function getLogs() {
|
|
397
|
-
return _getLogs.apply(this, arguments);
|
|
398
|
-
}
|
|
399
|
-
return getLogs;
|
|
400
|
-
}();
|
|
401
|
-
_proto.getLogsByRunId = /*#__PURE__*/function () {
|
|
402
|
-
var _getLogsByRunId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
403
|
-
var runId, allLogs;
|
|
404
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
405
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
406
|
-
case 0:
|
|
407
|
-
runId = _ref2.runId;
|
|
408
|
-
_context2.prev = 1;
|
|
409
|
-
_context2.next = 4;
|
|
410
|
-
return this.getLogs();
|
|
411
|
-
case 4:
|
|
412
|
-
allLogs = _context2.sent;
|
|
413
|
-
return _context2.abrupt("return", allLogs.filter(function (log) {
|
|
414
|
-
return (log == null ? void 0 : log.runId) === runId;
|
|
415
|
-
}) || []);
|
|
416
|
-
case 8:
|
|
417
|
-
_context2.prev = 8;
|
|
418
|
-
_context2.t0 = _context2["catch"](1);
|
|
419
|
-
console.error('Error getting logs by runId from Upstash:', _context2.t0);
|
|
420
|
-
return _context2.abrupt("return", []);
|
|
421
|
-
case 12:
|
|
422
|
-
case "end":
|
|
423
|
-
return _context2.stop();
|
|
424
|
-
}
|
|
425
|
-
}, _callee2, this, [[1, 8]]);
|
|
426
|
-
}));
|
|
427
|
-
function getLogsByRunId(_x) {
|
|
428
|
-
return _getLogsByRunId.apply(this, arguments);
|
|
429
|
-
}
|
|
430
|
-
return getLogsByRunId;
|
|
431
|
-
}();
|
|
432
|
-
return FileTransport;
|
|
433
|
-
}(LoggerTransport);
|
|
434
|
-
|
|
435
|
-
var UpstashTransport = /*#__PURE__*/function (_LoggerTransport) {
|
|
436
|
-
function UpstashTransport(opts) {
|
|
437
|
-
var _this;
|
|
438
|
-
_this = _LoggerTransport.call(this, {
|
|
439
|
-
objectMode: true
|
|
440
|
-
}) || this;
|
|
441
|
-
_this.upstashUrl = void 0;
|
|
442
|
-
_this.upstashToken = void 0;
|
|
443
|
-
_this.listName = void 0;
|
|
444
|
-
_this.maxListLength = void 0;
|
|
445
|
-
_this.batchSize = void 0;
|
|
446
|
-
_this.flushInterval = void 0;
|
|
447
|
-
_this.logBuffer = void 0;
|
|
448
|
-
_this.lastFlush = void 0;
|
|
449
|
-
_this.flushIntervalId = void 0;
|
|
450
|
-
if (!opts.upstashUrl || !opts.upstashToken) {
|
|
451
|
-
throw new Error('Upstash URL and token are required');
|
|
452
|
-
}
|
|
453
|
-
_this.upstashUrl = opts.upstashUrl;
|
|
454
|
-
_this.upstashToken = opts.upstashToken;
|
|
455
|
-
_this.listName = opts.listName || 'application-logs';
|
|
456
|
-
_this.maxListLength = opts.maxListLength || 10000;
|
|
457
|
-
_this.batchSize = opts.batchSize || 100;
|
|
458
|
-
_this.flushInterval = opts.flushInterval || 10000;
|
|
459
|
-
_this.logBuffer = [];
|
|
460
|
-
_this.lastFlush = Date.now();
|
|
461
|
-
// Start flush interval
|
|
462
|
-
_this.flushIntervalId = setInterval(function () {
|
|
463
|
-
_this._flush()["catch"](function (err) {
|
|
464
|
-
console.error('Error flushing logs to Upstash:', err);
|
|
465
|
-
});
|
|
466
|
-
}, _this.flushInterval);
|
|
467
|
-
return _this;
|
|
468
|
-
}
|
|
469
|
-
_inheritsLoose(UpstashTransport, _LoggerTransport);
|
|
470
|
-
var _proto = UpstashTransport.prototype;
|
|
471
|
-
_proto.executeUpstashCommand = /*#__PURE__*/function () {
|
|
472
|
-
var _executeUpstashCommand = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(command) {
|
|
473
|
-
var response;
|
|
474
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
475
|
-
while (1) switch (_context.prev = _context.next) {
|
|
476
|
-
case 0:
|
|
477
|
-
_context.next = 2;
|
|
478
|
-
return fetch(this.upstashUrl + "/pipeline", {
|
|
479
|
-
method: 'POST',
|
|
480
|
-
headers: {
|
|
481
|
-
Authorization: "Bearer " + this.upstashToken,
|
|
482
|
-
'Content-Type': 'application/json'
|
|
483
|
-
},
|
|
484
|
-
body: JSON.stringify([command])
|
|
485
|
-
});
|
|
486
|
-
case 2:
|
|
487
|
-
response = _context.sent;
|
|
488
|
-
if (response.ok) {
|
|
489
|
-
_context.next = 5;
|
|
490
|
-
break;
|
|
491
|
-
}
|
|
492
|
-
throw new Error("Failed to execute Upstash command: " + response.statusText);
|
|
493
|
-
case 5:
|
|
494
|
-
return _context.abrupt("return", response.json());
|
|
495
|
-
case 6:
|
|
496
|
-
case "end":
|
|
497
|
-
return _context.stop();
|
|
498
|
-
}
|
|
499
|
-
}, _callee, this);
|
|
500
|
-
}));
|
|
501
|
-
function executeUpstashCommand(_x) {
|
|
502
|
-
return _executeUpstashCommand.apply(this, arguments);
|
|
503
|
-
}
|
|
504
|
-
return executeUpstashCommand;
|
|
505
|
-
}();
|
|
506
|
-
_proto._flush = /*#__PURE__*/function () {
|
|
507
|
-
var _flush2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
508
|
-
var now, logs, command, _this$logBuffer;
|
|
509
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
510
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
511
|
-
case 0:
|
|
512
|
-
if (!(this.logBuffer.length === 0)) {
|
|
513
|
-
_context2.next = 2;
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
516
|
-
return _context2.abrupt("return");
|
|
517
|
-
case 2:
|
|
518
|
-
now = Date.now();
|
|
519
|
-
logs = this.logBuffer.splice(0, this.batchSize);
|
|
520
|
-
_context2.prev = 4;
|
|
521
|
-
// Prepare the Upstash Redis command
|
|
522
|
-
command = ['LPUSH', this.listName].concat(logs.map(function (log) {
|
|
523
|
-
return JSON.stringify(log);
|
|
524
|
-
})); // Trim the list if it exceeds maxListLength
|
|
525
|
-
if (this.maxListLength > 0) {
|
|
526
|
-
command.push('LTRIM', this.listName, 0, this.maxListLength - 1);
|
|
527
|
-
}
|
|
528
|
-
// Send logs to Upstash Redis
|
|
529
|
-
_context2.next = 9;
|
|
530
|
-
return this.executeUpstashCommand(command);
|
|
531
|
-
case 9:
|
|
532
|
-
this.lastFlush = now;
|
|
533
|
-
_context2.next = 16;
|
|
534
|
-
break;
|
|
535
|
-
case 12:
|
|
536
|
-
_context2.prev = 12;
|
|
537
|
-
_context2.t0 = _context2["catch"](4);
|
|
538
|
-
// On error, put logs back in the buffer
|
|
539
|
-
(_this$logBuffer = this.logBuffer).unshift.apply(_this$logBuffer, logs);
|
|
540
|
-
throw _context2.t0;
|
|
541
|
-
case 16:
|
|
542
|
-
case "end":
|
|
543
|
-
return _context2.stop();
|
|
544
|
-
}
|
|
545
|
-
}, _callee2, this, [[4, 12]]);
|
|
546
|
-
}));
|
|
547
|
-
function _flush() {
|
|
548
|
-
return _flush2.apply(this, arguments);
|
|
549
|
-
}
|
|
550
|
-
return _flush;
|
|
551
|
-
}();
|
|
552
|
-
_proto._transform = function _transform(chunk, _enc, cb) {
|
|
553
|
-
try {
|
|
554
|
-
// Parse the log line if it's a string
|
|
555
|
-
var log = typeof chunk === 'string' ? JSON.parse(chunk) : chunk;
|
|
556
|
-
// Add timestamp if not present
|
|
557
|
-
if (!log.time) {
|
|
558
|
-
log.time = Date.now();
|
|
559
|
-
}
|
|
560
|
-
// Add to buffer
|
|
561
|
-
this.logBuffer.push(log);
|
|
562
|
-
// Flush if buffer reaches batch size
|
|
563
|
-
if (this.logBuffer.length >= this.batchSize) {
|
|
564
|
-
this._flush()["catch"](function (err) {
|
|
565
|
-
console.error('Error flushing logs to Upstash:', err);
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
// Pass through the log
|
|
569
|
-
cb(null, chunk);
|
|
570
|
-
} catch (error) {
|
|
571
|
-
cb(error);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
_proto._destroy = function _destroy(err, cb) {
|
|
575
|
-
clearInterval(this.flushIntervalId);
|
|
576
|
-
// Final flush
|
|
577
|
-
if (this.logBuffer.length > 0) {
|
|
578
|
-
this._flush().then(function () {
|
|
579
|
-
return cb(err);
|
|
580
|
-
})["catch"](function (flushErr) {
|
|
581
|
-
console.error('Error in final flush:', flushErr);
|
|
582
|
-
cb(err || flushErr);
|
|
583
|
-
});
|
|
584
|
-
} else {
|
|
585
|
-
cb(err);
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
_proto.getLogs = /*#__PURE__*/function () {
|
|
589
|
-
var _getLogs = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
590
|
-
var _response$, command, response;
|
|
591
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
592
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
593
|
-
case 0:
|
|
594
|
-
_context3.prev = 0;
|
|
595
|
-
// Get all logs from the list
|
|
596
|
-
command = ['LRANGE', this.listName, 0, -1];
|
|
597
|
-
_context3.next = 4;
|
|
598
|
-
return this.executeUpstashCommand(command);
|
|
599
|
-
case 4:
|
|
600
|
-
response = _context3.sent;
|
|
601
|
-
return _context3.abrupt("return", response == null || (_response$ = response[0]) == null ? void 0 : _response$.result.map(function (log) {
|
|
602
|
-
try {
|
|
603
|
-
return JSON.parse(log);
|
|
604
|
-
} catch (e) {
|
|
605
|
-
return '';
|
|
606
|
-
}
|
|
607
|
-
}));
|
|
608
|
-
case 8:
|
|
609
|
-
_context3.prev = 8;
|
|
610
|
-
_context3.t0 = _context3["catch"](0);
|
|
611
|
-
console.error('Error getting logs from Upstash:', _context3.t0);
|
|
612
|
-
return _context3.abrupt("return", []);
|
|
613
|
-
case 12:
|
|
614
|
-
case "end":
|
|
615
|
-
return _context3.stop();
|
|
616
|
-
}
|
|
617
|
-
}, _callee3, this, [[0, 8]]);
|
|
618
|
-
}));
|
|
619
|
-
function getLogs() {
|
|
620
|
-
return _getLogs.apply(this, arguments);
|
|
621
|
-
}
|
|
622
|
-
return getLogs;
|
|
623
|
-
}();
|
|
624
|
-
_proto.getLogsByRunId = /*#__PURE__*/function () {
|
|
625
|
-
var _getLogsByRunId = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
|
|
626
|
-
var runId, allLogs;
|
|
627
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
628
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
629
|
-
case 0:
|
|
630
|
-
runId = _ref.runId;
|
|
631
|
-
_context4.prev = 1;
|
|
632
|
-
_context4.next = 4;
|
|
633
|
-
return this.getLogs();
|
|
634
|
-
case 4:
|
|
635
|
-
allLogs = _context4.sent;
|
|
636
|
-
return _context4.abrupt("return", allLogs.filter(function (log) {
|
|
637
|
-
var _log$msg;
|
|
638
|
-
return ((_log$msg = log.msg) == null ? void 0 : _log$msg.runId) === runId;
|
|
639
|
-
}) || []);
|
|
640
|
-
case 8:
|
|
641
|
-
_context4.prev = 8;
|
|
642
|
-
_context4.t0 = _context4["catch"](1);
|
|
643
|
-
console.error('Error getting logs by runId from Upstash:', _context4.t0);
|
|
644
|
-
return _context4.abrupt("return", []);
|
|
645
|
-
case 12:
|
|
646
|
-
case "end":
|
|
647
|
-
return _context4.stop();
|
|
648
|
-
}
|
|
649
|
-
}, _callee4, this, [[1, 8]]);
|
|
650
|
-
}));
|
|
651
|
-
function getLogsByRunId(_x2) {
|
|
652
|
-
return _getLogsByRunId.apply(this, arguments);
|
|
653
|
-
}
|
|
654
|
-
return getLogsByRunId;
|
|
655
|
-
}();
|
|
656
|
-
return UpstashTransport;
|
|
657
|
-
}(LoggerTransport);
|
|
658
|
-
|
|
659
|
-
export { FileTransport, UpstashTransport };
|
|
660
|
-
//# sourceMappingURL=loggers.esm.js.map
|