logtail/ts/index.ts
2021-07-07 00:06:12 +02:00

39 lines
1.2 KiB
TypeScript

import * as plugins from './logtail.plugins';
export class LogTailAccount {
private token: string;
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,
});
console.log(response.statusCode);
}
public get smartlogDestination(): plugins.smartlogInterfaces.ILogDestination {
return {
handleLog: async (logPackage: plugins.smartlogInterfaces.ILogPackage) => {
await this.log(logPackage);
}
}
}
}