fix(core): update
This commit is contained in:
parent
cb4cfaca09
commit
d846b100d2
14
package-lock.json
generated
14
package-lock.json
generated
@ -137,12 +137,20 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
"@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": {
|
"@pushrocks/smartlog-interfaces": {
|
||||||
"version": "1.0.15",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.0.tgz",
|
||||||
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ=="
|
"integrity": "sha512-rk3uEp78AXLULS81SUe6YtZvyQiDImuJu/zxnIzzUFDB6ciisqtJ1qVcHYbVsW/kImeo8vBFlQyKY9/YaNgkDw=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartpath": {
|
"@pushrocks/smartpath": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.2",
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.15",
|
"@pushrocks/smartlog-interfaces": "^2.0.0",
|
||||||
"@types/elasticsearch": "^5.0.28",
|
"@types/elasticsearch": "^5.0.28",
|
||||||
"elasticsearch": "^15.2.0"
|
"elasticsearch": "^15.2.0"
|
||||||
}
|
}
|
||||||
|
19
test/test.ts
19
test/test.ts
@ -12,20 +12,23 @@ tap.test('first test', async () => {
|
|||||||
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
|
||||||
logContext: {
|
|
||||||
company: 'Lossless GmbH',
|
|
||||||
runtime: 'node',
|
|
||||||
containerName: 'testContainer',
|
|
||||||
environment: 'test'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
expect(testElasticLog).to.be.instanceOf(elasticlog.ElasticLog);
|
expect(testElasticLog).to.be.instanceOf(elasticlog.ElasticLog);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message to Elasticsearch', async () => {
|
tap.test('should send a message to Elasticsearch', async () => {
|
||||||
testElasticLog.log({
|
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'
|
message: 'hi, this is a testMessage'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// interfaces
|
// interfaces
|
||||||
import { Client as ElasticClient } from 'elasticsearch';
|
import { Client as ElasticClient } from 'elasticsearch';
|
||||||
import { ILogContext } from '@pushrocks/smartlog-interfaces';
|
import { ILogContext, ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
// other classes
|
// other classes
|
||||||
import { LogScheduler } from './elasticlog.classes.logscheduler';
|
import { LogScheduler } from './elasticlog.classes.logscheduler';
|
||||||
@ -16,12 +16,10 @@ export interface IElasticLogConstructorOptions {
|
|||||||
ssl: boolean;
|
ssl: boolean;
|
||||||
user?: string;
|
user?: string;
|
||||||
pass?: string;
|
pass?: string;
|
||||||
logContext: ILogContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ElasticLog<T> {
|
export class ElasticLog<T> {
|
||||||
client: ElasticClient;
|
client: ElasticClient;
|
||||||
logContext: ILogContext;
|
|
||||||
logScheduler = new LogScheduler(this);
|
logScheduler = new LogScheduler(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +27,6 @@ export class ElasticLog<T> {
|
|||||||
* @param optionsArg
|
* @param optionsArg
|
||||||
*/
|
*/
|
||||||
constructor(optionsArg: IElasticLogConstructorOptions) {
|
constructor(optionsArg: IElasticLogConstructorOptions) {
|
||||||
this.logContext = optionsArg.logContext;
|
|
||||||
this.client = new ElasticClient({
|
this.client = new ElasticClient({
|
||||||
host: this.computeHostString(optionsArg),
|
host: this.computeHostString(optionsArg),
|
||||||
log: 'trace'
|
log: 'trace'
|
||||||
@ -53,10 +50,10 @@ export class ElasticLog<T> {
|
|||||||
return hostString;
|
return hostString;
|
||||||
}
|
}
|
||||||
|
|
||||||
async log(logObject: IStandardLogParams, scheduleOverwrite = false) {
|
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
if (this.logScheduler.logsScheduled && !scheduleOverwrite) {
|
if (this.logScheduler.logsScheduled && !scheduleOverwrite) {
|
||||||
this.logScheduler.scheduleLog(logObject);
|
this.logScheduler.scheduleLog(logPackageArg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.client.index(
|
this.client.index(
|
||||||
@ -67,20 +64,20 @@ export class ElasticLog<T> {
|
|||||||
type: 'log',
|
type: 'log',
|
||||||
body: {
|
body: {
|
||||||
'@timestamp': now.toISOString(),
|
'@timestamp': now.toISOString(),
|
||||||
zone: this.logContext.zone,
|
zone: logPackageArg.context.zone,
|
||||||
container: this.logContext.containerName,
|
container: logPackageArg.context.containerName,
|
||||||
environment: this.logContext.environment,
|
environment: logPackageArg.context.environment,
|
||||||
severity: logObject.severity,
|
severity: logPackageArg.level,
|
||||||
message: logObject.message
|
message: logPackageArg.message
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error, response) => {
|
(error, response) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('ElasticLog encountered an error:');
|
console.log('ElasticLog encountered an error:');
|
||||||
console.log(error);
|
console.log(error);
|
||||||
this.logScheduler.addFailedLog(logObject);
|
this.logScheduler.addFailedLog(logPackageArg);
|
||||||
} else {
|
} else {
|
||||||
console.log(`ElasticLog: ${logObject.message}`);
|
console.log(`ElasticLog: ${logPackageArg.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user