smartlog-destination-clickh.../ts/index.ts

31 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-07-26 11:43:23 +00:00
import * as plugins from './slclick.plugins.js';
export class SmartlogDestinationClickhouse implements plugins.smartlogInterfaces.ILogDestination {
// STATIC
2022-08-05 11:38:12 +00:00
public static async createAndStart(
optionsArg: plugins.smartclickhouse.IClickhouseConstructorOptions
) {
2022-07-26 11:43:23 +00:00
const destinationClickhouse = new SmartlogDestinationClickhouse(optionsArg);
await destinationClickhouse.start();
return destinationClickhouse;
}
2022-08-05 11:38:12 +00:00
2022-07-26 11:43:23 +00:00
// INSTANCE
private smartclickhouseDb: plugins.smartclickhouse.SmartClickHouseDb;
private logTable: plugins.smartclickhouse.TimeDataTable;
constructor(options: plugins.smartclickhouse.IClickhouseConstructorOptions) {
this.smartclickhouseDb = new plugins.smartclickhouse.SmartClickHouseDb(options);
}
public async start() {
await this.smartclickhouseDb.start();
this.logTable = await this.smartclickhouseDb.getTable('logs');
}
2022-08-05 11:38:12 +00:00
public async handleLog(
logPackage: plugins.smartlogInterfaces.ILogPackage<unknown>
): Promise<void> {
2022-07-26 11:43:23 +00:00
await this.logTable.addData(logPackage);
2022-08-05 11:38:12 +00:00
}
2022-07-26 11:43:23 +00:00
}