fix(core): update

This commit is contained in:
Philipp Kunz 2018-11-03 23:45:21 +01:00
parent cb4cfaca09
commit d846b100d2
4 changed files with 33 additions and 25 deletions

14
package-lock.json generated
View File

@ -137,12 +137,20 @@
"dev": true,
"requires": {
"@pushrocks/smartlog-interfaces": "^1.0.9"
},
"dependencies": {
"@pushrocks/smartlog-interfaces": {
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ==",
"dev": true
}
}
},
"@pushrocks/smartlog-interfaces": {
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ=="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.0.tgz",
"integrity": "sha512-rk3uEp78AXLULS81SUe6YtZvyQiDImuJu/zxnIzzUFDB6ciisqtJ1qVcHYbVsW/kImeo8vBFlQyKY9/YaNgkDw=="
},
"@pushrocks/smartpath": {
"version": "4.0.1",

View File

@ -24,7 +24,7 @@
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartlog-interfaces": "^1.0.15",
"@pushrocks/smartlog-interfaces": "^2.0.0",
"@types/elasticsearch": "^5.0.28",
"elasticsearch": "^15.2.0"
}

View File

@ -12,20 +12,23 @@ tap.test('first test', async () => {
port: parseInt(process.env.ELK_PORT, 10),
ssl: true,
user: process.env.ELK_USER,
pass: process.env.ELK_PASS,
logContext: {
company: 'Lossless GmbH',
runtime: 'node',
containerName: 'testContainer',
environment: 'test'
}
pass: process.env.ELK_PASS
});
expect(testElasticLog).to.be.instanceOf(elasticlog.ElasticLog);
});
tap.test('should send a message to Elasticsearch', async () => {
testElasticLog.log({
severity: 'log',
type: 'increment',
level: 'info',
context: {
company: 'Lossless GmbH',
companyunit: 'lossless.cloud',
containerName: 'testcontainer',
environment: 'test',
runtime: 'node',
zone: 'ship.zone',
},
message: 'hi, this is a testMessage'
});
});

View File

@ -1,6 +1,6 @@
// interfaces
import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext } from '@pushrocks/smartlog-interfaces';
import { ILogContext, ILogPackage } from '@pushrocks/smartlog-interfaces';
// other classes
import { LogScheduler } from './elasticlog.classes.logscheduler';
@ -16,12 +16,10 @@ export interface IElasticLogConstructorOptions {
ssl: boolean;
user?: string;
pass?: string;
logContext: ILogContext;
}
export class ElasticLog<T> {
client: ElasticClient;
logContext: ILogContext;
logScheduler = new LogScheduler(this);
/**
@ -29,7 +27,6 @@ export class ElasticLog<T> {
* @param optionsArg
*/
constructor(optionsArg: IElasticLogConstructorOptions) {
this.logContext = optionsArg.logContext;
this.client = new ElasticClient({
host: this.computeHostString(optionsArg),
log: 'trace'
@ -53,10 +50,10 @@ export class ElasticLog<T> {
return hostString;
}
async log(logObject: IStandardLogParams, scheduleOverwrite = false) {
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
const now = new Date();
if (this.logScheduler.logsScheduled && !scheduleOverwrite) {
this.logScheduler.scheduleLog(logObject);
this.logScheduler.scheduleLog(logPackageArg);
return;
}
this.client.index(
@ -67,20 +64,20 @@ export class ElasticLog<T> {
type: 'log',
body: {
'@timestamp': now.toISOString(),
zone: this.logContext.zone,
container: this.logContext.containerName,
environment: this.logContext.environment,
severity: logObject.severity,
message: logObject.message
zone: logPackageArg.context.zone,
container: logPackageArg.context.containerName,
environment: logPackageArg.context.environment,
severity: logPackageArg.level,
message: logPackageArg.message
}
},
(error, response) => {
if (error) {
console.log('ElasticLog encountered an error:');
console.log(error);
this.logScheduler.addFailedLog(logObject);
this.logScheduler.addFailedLog(logPackageArg);
} else {
console.log(`ElasticLog: ${logObject.message}`);
console.log(`ElasticLog: ${logPackageArg.message}`);
}
}
);