elasticsearch/dist/elasticlog.classes.elasticlog.js

63 lines
4.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// interfaces
const elasticsearch_1 = require("elasticsearch");
class ElasticLog {
/**
* sets up an instance of Elastic log
* @param optionsArg
*/
constructor(optionsArg) {
this.logScheduler = new LogScheduler();
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) {
const now = new Date();
this.client.index({
index: `logs-${now.getFullYear()}.${now.getMonth() + 1}.${now.getDate()}`,
type: 'log',
body: {
'@timestamp': now.toISOString(),
container: this.logContext.containerName,
environment: this.logContext.environment,
severity: logObject.severity,
message: logObject.message
}
}, (error, response) => {
if (error) {
console.log(error);
this.logScheduler.addFailedLog(logObject);
}
});
}
}
exports.ElasticLog = ElasticLog;
;
class LogScheduler {
addFailedLog(objectArg) {
}
}
exports.LogScheduler = LogScheduler;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWxhc3RpY2xvZy5jbGFzc2VzLmVsYXN0aWNsb2cuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9lbGFzdGljbG9nLmNsYXNzZXMuZWxhc3RpY2xvZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLGFBQWE7QUFDYixpREFBdUQ7QUF3QnZEO0lBS0U7OztPQUdHO0lBQ0gsWUFBYSxVQUF5QztRQU50RCxpQkFBWSxHQUFHLElBQUksWUFBWSxFQUFFLENBQUE7UUFPL0IsSUFBSSxDQUF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