fix(core): update

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

8
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "@pushrocks/elasticlog", "name": "@mojoio/elasticsearch",
"version": "1.0.16", "version": "1.0.16",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
@ -148,9 +148,9 @@
} }
}, },
"@pushrocks/smartlog-interfaces": { "@pushrocks/smartlog-interfaces": {
"version": "2.0.1", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.1.tgz", "resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz",
"integrity": "sha512-c9onE52z/5fGX5uEvaI/rXbcC6n7PkLrNjehRM+6JsK7HIbdAzrgY1PGrqUfW0a03hSe03mFcggORID+fQI4tA==" "integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ=="
}, },
"@pushrocks/smartpath": { "@pushrocks/smartpath": {
"version": "4.0.1", "version": "4.0.1",

View File

@ -1,5 +1,5 @@
{ {
"name": "@pushrocks/elasticlog", "name": "@mojoio/elasticsearch",
"version": "1.0.16", "version": "1.0.16",
"private": false, "private": false,
"description": "log to elasticsearch in a kibana compatible format", "description": "log to elasticsearch in a kibana compatible format",
@ -24,8 +24,8 @@
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartlog-interfaces": "^2.0.1", "@pushrocks/smartlog-interfaces": "^2.0.2",
"@types/elasticsearch": "^5.0.28", "@types/elasticsearch": "^5.0.28",
"elasticsearch": "^15.2.0" "elasticsearch": "^15.2.0"
} }
} }

View File

@ -1,24 +1,25 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv'; import { Qenv } from '@pushrocks/qenv';
import * as elasticlog from '../ts/index'; import * as elasticsearch from '../ts/index';
const testQenv = new Qenv('./', './.nogit/'); const testQenv = new Qenv('./', './.nogit/');
let testElasticLog: elasticlog.ElasticLog<any>; let testElasticLog: elasticsearch.ElasticSearch<any>;
tap.test('first test', async () => { tap.test('first test', async () => {
testElasticLog = new elasticlog.ElasticLog({ testElasticLog = new elasticsearch.ElasticSearch({
domain: process.env.ELK_DOMAIN, domain: process.env.ELK_DOMAIN,
port: parseInt(process.env.ELK_PORT, 10), port: parseInt(process.env.ELK_PORT, 10),
ssl: true, ssl: true,
user: process.env.ELK_USER, user: process.env.ELK_USER,
pass: process.env.ELK_PASS 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 () => { tap.test('should send a message to Elasticsearch', async () => {
testElasticLog.log({ testElasticLog.log({
timestamp: Date.now(),
type: 'increment', type: 'increment',
level: 'info', level: 'info',
context: { context: {
@ -27,7 +28,7 @@ tap.test('should send a message to Elasticsearch', async () => {
containerName: 'testcontainer', containerName: 'testcontainer',
environment: 'test', environment: 'test',
runtime: 'node', runtime: 'node',
zone: 'ship.zone', zone: 'ship.zone'
}, },
message: 'hi, this is a testMessage' message: 'hi, this is a testMessage'
}); });

View File

@ -1,9 +1,9 @@
// interfaces // interfaces
import { Client as ElasticClient } from 'elasticsearch'; import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext, ILogPackage } from '@pushrocks/smartlog-interfaces'; import { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
// other classes // other classes
import { LogScheduler } from './elasticlog.classes.logscheduler'; import { LogScheduler } from './elasticsearch.classes.logscheduler';
export interface IStandardLogParams { export interface IStandardLogParams {
message: string; message: string;
@ -18,7 +18,7 @@ export interface IElasticLogConstructorOptions {
pass?: string; pass?: string;
} }
export class ElasticLog<T> { export class ElasticSearch<T> {
client: ElasticClient; client: ElasticClient;
logScheduler = new LogScheduler(this); logScheduler = new LogScheduler(this);
@ -58,17 +58,13 @@ export class ElasticLog<T> {
} }
this.client.index( 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() '0' + now.getDate()
).slice(-2)}`, ).slice(-2)}`,
type: 'log', type: 'log',
body: { body: {
'@timestamp': now.toISOString(), '@timestamp': new Date(logPackageArg.timestamp).toISOString(),
zone: logPackageArg.context.zone, ...logPackageArg
container: logPackageArg.context.containerName,
environment: logPackageArg.context.environment,
severity: logPackageArg.level,
message: logPackageArg.message
} }
}, },
(error, response) => { (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 { export class LogScheduler {
elasticLogRef: ElasticLog<any>; elasticLogRef: ElasticSearch<any>;
logsScheduled = false; logsScheduled = false;
logStorage: any[] = []; logStorage: any[] = [];
constructor(elasticLogRefArg: ElasticLog<any>) { constructor(elasticLogRefArg: ElasticSearch<any>) {
this.elasticLogRef = elasticLogRefArg; this.elasticLogRef = elasticLogRefArg;
} }

View File

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