fix(core): update

This commit is contained in:
2018-08-12 16:42:09 +02:00
parent fa92362547
commit 34ffce83bd
18 changed files with 1270 additions and 720 deletions

View File

@@ -1,8 +1,9 @@
// interfaces
import { Client as ElasticClient } from "elasticsearch";
import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext } from '@pushrocks/smartlog-interfaces';
// other classes
import { LogScheduler } from "./elasticlog.classes.logscheduler";
import { LogScheduler } from './elasticlog.classes.logscheduler';
export interface IStandardLogParams {
message: string;
@@ -15,12 +16,12 @@ export interface IElasticLogConstructorOptions {
ssl: boolean;
user?: string;
pass?: string;
logContext: LogContext;
logContext: ILogContext;
}
export class ElasticLog<T> {
client: ElasticClient;
logContext: LogContext;
logContext: ILogContext;
logScheduler = new LogScheduler(this);
/**
@@ -31,7 +32,7 @@ export class ElasticLog<T> {
this.logContext = optionsArg.logContext;
this.client = new ElasticClient({
host: this.computeHostString(optionsArg),
log: "trace"
log: 'trace'
});
}
@@ -60,12 +61,12 @@ export class ElasticLog<T> {
}
this.client.index(
{
index: `logs-${now.getFullYear()}.${("0" + (now.getMonth() + 1)).slice(
index: `logs-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(
-2
)}.${now.getDate()}`,
type: "log",
type: 'log',
body: {
"@timestamp": now.toISOString(),
'@timestamp': now.toISOString(),
zone: this.logContext.zone,
container: this.logContext.containerName,
environment: this.logContext.environment,
@@ -75,7 +76,7 @@ export class ElasticLog<T> {
},
(error, response) => {
if (error) {
console.log("ElasticLog encountered an error:");
console.log('ElasticLog encountered an error:');
console.log(error);
this.logScheduler.addFailedLog(logObject);
} else {

View File

@@ -1,7 +1,4 @@
import {
ElasticLog,
IStandardLogParams
} from "./elasticlog.classes.elasticlog";
import { ElasticLog, IStandardLogParams } from './elasticlog.classes.elasticlog';
export class LogScheduler {
elasticLogRef: ElasticLog<any>;
@@ -28,10 +25,10 @@ export class LogScheduler {
this.elasticLogRef.log(logObject, true);
}
if (this.logStorage.length === 0) {
console.log("ElasticLog retry success!!!");
console.log('ElasticLog retry success!!!');
this.logsScheduled = false;
} else {
console.log("ElasticLog retry failed");
console.log('ElasticLog retry failed');
this.setRetry();
}
}, 5000);
@@ -39,7 +36,7 @@ export class LogScheduler {
deferSend() {
if (!this.logsScheduled) {
console.log("Retry ElasticLog in 5 seconds!");
console.log('Retry ElasticLog in 5 seconds!');
this.logsScheduled = true;
this.setRetry();
}

View File

@@ -1,3 +1,4 @@
import * as elasticsearch from "elasticsearch";
import * as smartdelay from "smartdelay";
export { elasticsearch, smartdelay };
import * as elasticsearch from 'elasticsearch';
import * as smartdelay from 'smartdelay';
import * as smartlogInterfaces from 'smartlog-interfaces';
export { elasticsearch, smartdelay, smartlogInterfaces };

View File

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