fix(core): update
This commit is contained in:
parent
44fccc252e
commit
4f1df305ed
8
package-lock.json
generated
8
package-lock.json
generated
@ -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",
|
||||
|
@ -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,7 +24,7 @@
|
||||
},
|
||||
"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"
|
||||
}
|
||||
|
11
test/test.ts
11
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<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'
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
export * from './elasticlog.classes.elasticlog';
|
||||
export * from './elasticsearch.classes.elasticsearch';
|
||||
|
Loading…
Reference in New Issue
Block a user