From 4f1df305ed09d1d2346db5aeb50162abd316ae21 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 7 Nov 2018 11:38:53 +0100 Subject: [PATCH] fix(core): update --- package-lock.json | 8 +++---- package.json | 6 ++--- test/test.ts | 11 +++++---- ...=> elasticsearch.classes.elasticsearch.ts} | 24 +++++++++++-------- ... => elasticsearch.classes.logscheduler.ts} | 6 ++--- ...og.plugins.ts => elasticsearch.plugins.ts} | 0 ts/index.ts | 2 +- 7 files changed, 31 insertions(+), 26 deletions(-) rename ts/{elasticlog.classes.elasticlog.ts => elasticsearch.classes.elasticsearch.ts} (78%) rename ts/{elasticlog.classes.logscheduler.ts => elasticsearch.classes.logscheduler.ts} (83%) rename ts/{elasticlog.plugins.ts => elasticsearch.plugins.ts} (100%) diff --git a/package-lock.json b/package-lock.json index c0d7c6c..778692e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@pushrocks/elasticlog", + "name": "@mojoio/elasticsearch", "version": "1.0.16", "lockfileVersion": 1, "requires": true, @@ -148,9 +148,9 @@ } }, "@pushrocks/smartlog-interfaces": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.1.tgz", - "integrity": "sha512-c9onE52z/5fGX5uEvaI/rXbcC6n7PkLrNjehRM+6JsK7HIbdAzrgY1PGrqUfW0a03hSe03mFcggORID+fQI4tA==" + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz", + "integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ==" }, "@pushrocks/smartpath": { "version": "4.0.1", diff --git a/package.json b/package.json index 9623bcd..cc2a579 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@pushrocks/elasticlog", + "name": "@mojoio/elasticsearch", "version": "1.0.16", "private": false, "description": "log to elasticsearch in a kibana compatible format", @@ -24,8 +24,8 @@ }, "dependencies": { "@pushrocks/smartdelay": "^2.0.2", - "@pushrocks/smartlog-interfaces": "^2.0.1", + "@pushrocks/smartlog-interfaces": "^2.0.2", "@types/elasticsearch": "^5.0.28", "elasticsearch": "^15.2.0" } -} +} \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index e2f93d6..830b2e7 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,24 +1,25 @@ import { expect, tap } from '@pushrocks/tapbundle'; import { Qenv } from '@pushrocks/qenv'; -import * as elasticlog from '../ts/index'; +import * as elasticsearch from '../ts/index'; const testQenv = new Qenv('./', './.nogit/'); -let testElasticLog: elasticlog.ElasticLog; +let testElasticLog: elasticsearch.ElasticSearch; tap.test('first test', async () => { - testElasticLog = new elasticlog.ElasticLog({ + testElasticLog = new elasticsearch.ElasticSearch({ domain: process.env.ELK_DOMAIN, port: parseInt(process.env.ELK_PORT, 10), ssl: true, user: process.env.ELK_USER, pass: process.env.ELK_PASS }); - expect(testElasticLog).to.be.instanceOf(elasticlog.ElasticLog); + expect(testElasticLog).to.be.instanceOf(elasticsearch.ElasticSearch); }); tap.test('should send a message to Elasticsearch', async () => { testElasticLog.log({ + timestamp: Date.now(), type: 'increment', level: 'info', context: { @@ -27,7 +28,7 @@ tap.test('should send a message to Elasticsearch', async () => { containerName: 'testcontainer', environment: 'test', runtime: 'node', - zone: 'ship.zone', + zone: 'ship.zone' }, message: 'hi, this is a testMessage' }); diff --git a/ts/elasticlog.classes.elasticlog.ts b/ts/elasticsearch.classes.elasticsearch.ts similarity index 78% rename from ts/elasticlog.classes.elasticlog.ts rename to ts/elasticsearch.classes.elasticsearch.ts index f649b8a..7daddee 100644 --- a/ts/elasticlog.classes.elasticlog.ts +++ b/ts/elasticsearch.classes.elasticsearch.ts @@ -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 { +export class ElasticSearch { client: ElasticClient; logScheduler = new LogScheduler(this); @@ -58,17 +58,13 @@ export class ElasticLog { } 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 { } ); } + + get logDestination (): ILogDestination { + return { + handleLog: (smartlogPackageArg: ILogPackage) => { + this.log(smartlogPackageArg); + } + } + } } diff --git a/ts/elasticlog.classes.logscheduler.ts b/ts/elasticsearch.classes.logscheduler.ts similarity index 83% rename from ts/elasticlog.classes.logscheduler.ts rename to ts/elasticsearch.classes.logscheduler.ts index be864b3..0d41f9a 100644 --- a/ts/elasticlog.classes.logscheduler.ts +++ b/ts/elasticsearch.classes.logscheduler.ts @@ -1,11 +1,11 @@ -import { ElasticLog, IStandardLogParams } from './elasticlog.classes.elasticlog'; +import { ElasticSearch, IStandardLogParams } from './elasticsearch.classes.elasticsearch'; export class LogScheduler { - elasticLogRef: ElasticLog; + elasticLogRef: ElasticSearch; logsScheduled = false; logStorage: any[] = []; - constructor(elasticLogRefArg: ElasticLog) { + constructor(elasticLogRefArg: ElasticSearch) { this.elasticLogRef = elasticLogRefArg; } diff --git a/ts/elasticlog.plugins.ts b/ts/elasticsearch.plugins.ts similarity index 100% rename from ts/elasticlog.plugins.ts rename to ts/elasticsearch.plugins.ts diff --git a/ts/index.ts b/ts/index.ts index f1b9faa..2e9f6c5 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1 +1 @@ -export * from './elasticlog.classes.elasticlog'; +export * from './elasticsearch.classes.elasticsearch';