cctail
Version:
Salesforce Commerce Cloud logs remote tail
46 lines (45 loc) • 1.81 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("./logger"));
const fluent = require('fluent-logger');
class LogFluent {
constructor(fConfig) {
this.enabled = fConfig.enabled;
this.host = fConfig.host || 'localhost';
this.port = fConfig.port || 24224;
this.reconnect_interval = fConfig.reconnect_interval || 600;
this.timeout = fConfig.timeout || 3.0;
this.tag_prefix = fConfig.tag_prefix || 'sfcc';
fluent.configure(this.tag_prefix, {
host: this.host,
port: this.port,
timeout: this.timeout,
reconnectInterval: this.reconnect_interval * 1000
});
}
output(hostname, logs, printnots, debug) {
logger_1.default.log(logger_1.default.debug, `Sending ${logs.length} new log records to FluentD this interval.`, debug);
for (let j = 0; j < logs.length; j++) {
let log = logs[j];
if (!printnots && !log.timestamp) {
// eslint-disable-next-line no-continue
continue;
}
try {
fluent.emit(log.logfile.substr(0, log.logfile.indexOf('-')), {
logfile: log.logfile,
level: log.level,
message: log.message.trim(),
hostname: hostname
}, fluent.EventTime.fromTimestamp(log.timestamp.valueOf()));
}
catch (err) {
logger_1.default.log('error', 'Send to FluentD failed with error: ' + err);
}
}
}
}
exports.default = LogFluent;