Compare commits

...

4 Commits

Author SHA1 Message Date
6ed2b6e993 1.0.17 2018-11-07 11:38:53 +01:00
4f1df305ed fix(core): update 2018-11-07 11:38:53 +01:00
44fccc252e 1.0.16 2018-11-04 02:42:08 +01:00
0854207a04 fix(core): update 2018-11-04 02:42:07 +01:00
7 changed files with 32 additions and 27 deletions

10
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/elasticlog",
"version": "1.0.15",
"name": "@mojoio/elasticsearch",
"version": "1.0.17",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -148,9 +148,9 @@
}
},
"@pushrocks/smartlog-interfaces": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.0.tgz",
"integrity": "sha512-rk3uEp78AXLULS81SUe6YtZvyQiDImuJu/zxnIzzUFDB6ciisqtJ1qVcHYbVsW/kImeo8vBFlQyKY9/YaNgkDw=="
"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",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/elasticlog",
"version": "1.0.15",
"name": "@mojoio/elasticsearch",
"version": "1.0.17",
"private": false,
"description": "log to elasticsearch in a kibana compatible format",
"main": "dist/index.js",
@ -24,7 +24,7 @@
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.2",
"@pushrocks/smartlog-interfaces": "^2.0.0",
"@pushrocks/smartlog-interfaces": "^2.0.2",
"@types/elasticsearch": "^5.0.28",
"elasticsearch": "^15.2.0"
}

View File

@ -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<any>;
let testElasticLog: elasticsearch.ElasticSearch<any>;
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'
});

View File

@ -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<T> {
export class ElasticSearch<T> {
client: ElasticClient;
logScheduler = new LogScheduler(this);
@ -58,17 +58,13 @@ export class ElasticLog<T> {
}
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<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 {
elasticLogRef: ElasticLog<any>;
elasticLogRef: ElasticSearch<any>;
logsScheduled = false;
logStorage: any[] = [];
constructor(elasticLogRefArg: ElasticLog<any>) {
constructor(elasticLogRefArg: ElasticSearch<any>) {
this.elasticLogRef = elasticLogRefArg;
}

View File

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