fix(core): update

This commit is contained in:
2018-11-07 11:38:53 +01:00
parent 44fccc252e
commit 4f1df305ed
7 changed files with 31 additions and 26 deletions

View File

@@ -1,9 +1,9 @@
// interfaces
import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext, ILogPackage } from '@pushrocks/smartlog-interfaces';
import { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
// other classes
import { LogScheduler } from './elasticlog.classes.logscheduler';
import { LogScheduler } from './elasticsearch.classes.logscheduler';
export interface IStandardLogParams {
message: string;
@@ -18,7 +18,7 @@ export interface IElasticLogConstructorOptions {
pass?: string;
}
export class ElasticLog<T> {
export class ElasticSearch<T> {
client: ElasticClient;
logScheduler = new LogScheduler(this);
@@ -58,17 +58,13 @@ export class ElasticLog<T> {
}
this.client.index(
{
index: `logstash-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(-2)}.${(
index: `smartlog-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(-2)}.${(
'0' + now.getDate()
).slice(-2)}`,
type: 'log',
body: {
'@timestamp': now.toISOString(),
zone: logPackageArg.context.zone,
container: logPackageArg.context.containerName,
environment: logPackageArg.context.environment,
severity: logPackageArg.level,
message: logPackageArg.message
'@timestamp': new Date(logPackageArg.timestamp).toISOString(),
...logPackageArg
}
},
(error, response) => {
@@ -82,4 +78,12 @@ export class ElasticLog<T> {
}
);
}
get logDestination (): ILogDestination {
return {
handleLog: (smartlogPackageArg: ILogPackage) => {
this.log(smartlogPackageArg);
}
}
}
}

View File

@@ -1,11 +1,11 @@
import { ElasticLog, IStandardLogParams } from './elasticlog.classes.elasticlog';
import { ElasticSearch, IStandardLogParams } from './elasticsearch.classes.elasticsearch';
export class LogScheduler {
elasticLogRef: ElasticLog<any>;
elasticLogRef: ElasticSearch<any>;
logsScheduled = false;
logStorage: any[] = [];
constructor(elasticLogRefArg: ElasticLog<any>) {
constructor(elasticLogRefArg: ElasticSearch<any>) {
this.elasticLogRef = elasticLogRefArg;
}

View File

@@ -1 +1 @@
export * from './elasticlog.classes.elasticlog';
export * from './elasticsearch.classes.elasticsearch';