fix(core): update

This commit is contained in:
Philipp Kunz 2018-11-07 12:44:49 +01:00
parent 6fde0544f5
commit cb63b305ad
9 changed files with 1 additions and 183 deletions

View File

@ -1,31 +0,0 @@
import { Client as ElasticClient } from 'elasticsearch';
import { ILogContext } from 'smartlog-interfaces';
import { LogScheduler } from './elasticlog.classes.logscheduler';
export interface IStandardLogParams {
message: string;
severity: string;
}
export interface IElasticLogConstructorOptions {
port: number;
domain: string;
ssl: boolean;
user?: string;
pass?: string;
logContext: ILogContext;
}
export declare class ElasticLog<T> {
client: ElasticClient;
logContext: ILogContext;
logScheduler: LogScheduler;
/**
* sets up an instance of Elastic log
* @param optionsArg
*/
constructor(optionsArg: IElasticLogConstructorOptions);
/**
* computes the host string from the constructor options
* @param optionsArg
*/
private computeHostString(optionsArg);
log(logObject: IStandardLogParams, scheduleOverwrite?: boolean): Promise<void>;
}

View File

@ -1,77 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// interfaces
const elasticsearch_1 = require("elasticsearch");
// other classes
const elasticlog_classes_logscheduler_1 = require("./elasticlog.classes.logscheduler");
class ElasticLog {
/**
* sets up an instance of Elastic log
* @param optionsArg
*/
constructor(optionsArg) {
this.logScheduler = new elasticlog_classes_logscheduler_1.LogScheduler(this);
this.logContext = optionsArg.logContext;
this.client = new elasticsearch_1.Client({
host: this.computeHostString(optionsArg),
log: 'trace'
});
}
/**
* computes the host string from the constructor options
* @param optionsArg
*/
computeHostString(optionsArg) {
let hostString = `${optionsArg.domain}:${optionsArg.port}`;
if (optionsArg.user && optionsArg.pass) {
hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`;
}
if (optionsArg.ssl) {
hostString = `https://${hostString}`;
}
else {
hostString = `http://${hostString}`;
}
return hostString;
}
log(logObject, scheduleOverwrite = false) {
return __awaiter(this, void 0, void 0, function* () {
const now = new Date();
if (this.logScheduler.logsScheduled && !scheduleOverwrite) {
this.logScheduler.scheduleLog(logObject);
return;
}
this.client.index({
index: `logs-${now.getFullYear()}.${('0' + (now.getMonth() + 1)).slice(-2)}.${now.getDate()}`,
type: 'log',
body: {
'@timestamp': now.toISOString(),
zone: this.logContext.zone,
container: this.logContext.containerName,
environment: this.logContext.environment,
severity: logObject.severity,
message: logObject.message
}
}, (error, response) => {
if (error) {
console.log('ElasticLog encountered an error:');
console.log(error);
this.logScheduler.addFailedLog(logObject);
}
else {
console.log(`ElasticLog: ${logObject.message}`);
}
});
});
}
}
exports.ElasticLog = ElasticLog;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWxhc3RpY2xvZy5jbGFzc2VzLmVsYXN0aWNsb2cuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lbGFzdGljbG9nLmNsYXNzZXMuZWxhc3RpY2xvZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsYUFBYTtBQUNiLGlEQUF3RDtBQUd4RCxnQkFBZ0I7QUFDaEIsdUZBQWlFO0FBZ0JqRTtJQUtFOzs7T0FHRztJQUNILFlBQVksVUFBeUM7UUFOckQsaUJBQVksR0FBRyxJQUFJLDhDQUFZLENBQUMsSUFBSSxDQUFDLENBQUM7UUFPcEMsSUFBSSxDQUFDLFVBQVUsR0FBRyxVQUFVLENBQUMsVUFBVSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxNQUFNLEdBQUcsSUFBSSxzQkFBYSxDQUFDO1lBQzlCLElBQUksRUFBRSxJQUFJLENBQUMsaUJBQWlCLENBQU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QUMsQ0FDRixDQUFDO1FBQ0osQ0FBQztLQUFBO0NBQ0Y7QUFsRUQsZ0NBa0VDIn0=

View File

@ -1,11 +0,0 @@
import { ElasticLog, IStandardLogParams } from './elasticlog.classes.elasticlog';
export declare class LogScheduler {
elasticLogRef: ElasticLog<any>;
logsScheduled: boolean;
logStorage: any[];
constructor(elasticLogRefArg: ElasticLog<any>);
addFailedLog(objectArg: any | IStandardLogParams): void;
scheduleLog(logObject: any): void;
setRetry(): void;
deferSend(): void;
}

View File

@ -1,42 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class LogScheduler {
constructor(elasticLogRefArg) {
this.logsScheduled = false;
this.logStorage = [];
this.elasticLogRef = elasticLogRefArg;
}
addFailedLog(objectArg) {
this.logStorage.push(objectArg);
this.setRetry();
}
scheduleLog(logObject) {
this.logStorage.push(logObject);
}
setRetry() {
setTimeout(() => {
const oldStorage = this.logStorage;
this.logStorage = [];
for (let logObject of oldStorage) {
this.elasticLogRef.log(logObject, true);
}
if (this.logStorage.length === 0) {
console.log('ElasticLog retry success!!!');
this.logsScheduled = false;
}
else {
console.log('ElasticLog retry failed');
this.setRetry();
}
}, 5000);
}
deferSend() {
if (!this.logsScheduled) {
console.log('Retry ElasticLog in 5 seconds!');
this.logsScheduled = true;
this.setRetry();
}
}
}
exports.LogScheduler = LogScheduler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWxhc3RpY2xvZy5jbGFzc2VzLmxvZ3NjaGVkdWxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2VsYXN0aWNsb2cuY2xhc3Nlcy5sb2dzY2hlZHVsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFFQTtJQUtFLFlBQVksZ0JBQWlDO1FBSDdDLGtCQUFhLEdBQUcsS0FBSyxDQUFDO1FBQ3RCLGVBQVUsR0FBVSxFQUFFLENBQUM7UU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QUM7SUFDWCxDQUFDO0lBRUQsU0FBUztRQUNQLEVBQUUsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLGFBQWEsQ0FBQyxDQUFDLENBQUM7WUFDeEIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxnQ0FBZ0MsQ0FBQyxDQUFDO1lBQzlDLElBQUksQ0FBQyxhQUFhLEdBQUcsSUFBSSxDQUFDO1lBQzFCLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztRQUNsQixDQUFDO0lBQ0gsQ0FBQztDQUNGO0FBekNELG9DQXlDQyJ9

View File

@ -1,4 +0,0 @@
import * as elasticsearch from 'elasticsearch';
import * as smartdelay from 'smartdelay';
import * as smartlogInterfaces from 'smartlog-interfaces';
export { elasticsearch, smartdelay, smartlogInterfaces };

View File

@ -1,9 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const elasticsearch = require("elasticsearch");
exports.elasticsearch = elasticsearch;
const smartdelay = require("smartdelay");
exports.smartdelay = smartdelay;
const smartlogInterfaces = require("smartlog-interfaces");
exports.smartlogInterfaces = smartlogInterfaces;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWxhc3RpY2xvZy5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvZWxhc3RpY2xvZy5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQStDO0FBR3RDLHNDQUFhO0FBRnRCLHlDQUF5QztBQUVqQixnQ0FBVTtBQURsQywwREFBMEQ7QUFDdEIsZ0RBQWtCIn0=

1
dist/index.d.ts vendored
View File

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

7
dist/index.js vendored
View File

@ -1,7 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./elasticlog.classes.elasticlog"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHFEQUFnRCJ9

View File

@ -10,7 +10,7 @@
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"format": "(gitzone format)", "format": "(gitzone format)",
"build": "echo \"Not needed for now\"" "build": "(tsbuild)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",