diff --git a/package-lock.json b/package-lock.json index de6aba2..d900811 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 4e613b0..2bf3c39 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/test/test.ts b/test/test.ts index e0a3f10..e2f93d6 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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' }); }); diff --git a/ts/elasticlog.classes.elasticlog.ts b/ts/elasticlog.classes.elasticlog.ts index 451d1ff..f649b8a 100644 --- a/ts/elasticlog.classes.elasticlog.ts +++ b/ts/elasticlog.classes.elasticlog.ts @@ -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 { client: ElasticClient; - logContext: ILogContext; logScheduler = new LogScheduler(this); /** @@ -29,7 +27,6 @@ export class ElasticLog { * @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 { 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 { 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}`); } } );