fix(core): update
This commit is contained in:
56
ts/index.ts
56
ts/index.ts
@ -2,30 +2,46 @@ import * as plugins from './logtail.plugins';
|
||||
|
||||
export class LogTailAccount {
|
||||
private token: string;
|
||||
|
||||
private timedAggregator = new plugins.lik.TimedAggregtor<plugins.smartlogInterfaces.ILogPackage<{[key: string]: any}>>({
|
||||
aggregationIntervalInMillis: 2000,
|
||||
functionForAggregation: async (logPackagesArg) => {
|
||||
const requestBody = [];
|
||||
let lastTimestamp: number = 0;
|
||||
for (const logPackageArg of logPackagesArg) {
|
||||
if (logPackageArg.timestamp === lastTimestamp) {
|
||||
logPackageArg.timestamp++;
|
||||
}
|
||||
lastTimestamp = logPackageArg.timestamp;
|
||||
requestBody.push({
|
||||
dt: new Date(logPackageArg.timestamp).toISOString(),
|
||||
level: logPackageArg.level,
|
||||
message: `${logPackageArg.context?.containerName}: ${logPackageArg.message}`,
|
||||
originalMessage: logPackageArg.message,
|
||||
context: logPackageArg.context,
|
||||
correlation: logPackageArg.correlation,
|
||||
data: logPackageArg.data,
|
||||
type: logPackageArg.type
|
||||
});
|
||||
}
|
||||
const response = await plugins.smartrequest.request('https://in.logtail.com', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${this.token}`
|
||||
},
|
||||
requestBody,
|
||||
keepAlive: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
constructor(logTailToken: string) {
|
||||
this.token = logTailToken;
|
||||
}
|
||||
|
||||
async log(logPackage: plugins.smartlogInterfaces.ILogPackage<{[key: string]: any}>) {
|
||||
const requestBody = {
|
||||
dt: new Date(logPackage.timestamp).toISOString(),
|
||||
level: logPackage.level,
|
||||
message: `${logPackage.context?.containerName}: ${logPackage.message}`,
|
||||
originalMessage: logPackage.message,
|
||||
context: logPackage.context,
|
||||
correlation: logPackage.correlation,
|
||||
data: logPackage.data,
|
||||
type: logPackage.type
|
||||
};
|
||||
const response = await plugins.smartrequest.request('https://in.logtail.com', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${this.token}`
|
||||
},
|
||||
requestBody,
|
||||
keepAlive: true,
|
||||
});
|
||||
async log(logPackageArg: plugins.smartlogInterfaces.ILogPackage<{[key: string]: any}>) {
|
||||
this.timedAggregator.add(logPackageArg);
|
||||
}
|
||||
|
||||
public get smartlogDestination(): plugins.smartlogInterfaces.ILogDestination {
|
||||
|
@ -1,7 +1,9 @@
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartlogInterfaces,
|
||||
smartrequest,
|
||||
}
|
Reference in New Issue
Block a user