38 lines
1.1 KiB
TypeScript
38 lines
1.1 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,
|
|
});
|
|
}
|
|
|
|
public get smartlogDestination(): plugins.smartlogInterfaces.ILogDestination {
|
|
return {
|
|
handleLog: async (logPackage: plugins.smartlogInterfaces.ILogPackage) => {
|
|
await this.log(logPackage);
|
|
}
|
|
}
|
|
}
|
|
} |