Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
projectFiles.forEach((watchItem, fName) => {
const relPath = path.relative(process.cwd(), fName);
if (watchItem.brokerRestart)
broker.logger.debug(` ${relPath}:`, kleur.grey("restart broker."));
else if (watchItem.allServices)
broker.logger.debug(` ${relPath}:`, kleur.grey("reload all services."));
else if (watchItem.services.length > 0) {
broker.logger.debug(` ${relPath}:`, kleur.grey(`reload ${watchItem.services.length} service(s) & ${watchItem.others.length} other(s).`)/*, watchItem.services, watchItem.others*/);
watchItem.services.forEach(svcFullname => broker.logger.debug(kleur.grey(` ${svcFullname}`)));
watchItem.others.forEach(filename => broker.logger.debug(kleur.grey(` ${path.relative(process.cwd(), filename)}`)));
}
// Create watcher
watchItem.watcher = fs.watch(fName, (eventType) => {
const relPath = path.relative(process.cwd(), fName);
broker.logger.info(kleur.magenta().bold(`The '${relPath}' file is changed. (Event: ${eventType})`));
// Clear from require cache
clearRequireCache(fName);
if (watchItem.others.length > 0) {
watchItem.others.forEach(f => clearRequireCache(f));
printRequest(id) {
const main = this.spans[id];
if (!main) return ; // Async span
const margin = 2 * 2;
const w = this.opts.width - margin;
this.drawTableTop();
const { total, depth } = this.getTraceInfo(main);
const truncatedID = this.getAlignedTexts(id, w - "ID: ".length - "Depth: ".length - (""+depth).length - "Total: ".length - (""+total).length - 2);
const line = kleur.grey("ID: ") + kleur.bold(truncatedID) + " " + kleur.grey("Depth: ") + kleur.bold(depth) + " " + kleur.grey("Total: ") + kleur.bold(total);
this.drawLine(line);
this.drawHorizonalLine();
this.printSpanTime(main, main, 1, null, {});
this.drawTableBottom();
}
function hotReloadService(service) {
const relPath = path.relative(process.cwd(), service.__filename);
broker.logger.info(`Hot reload '${service.name}' service...`, kleur.grey(relPath));
return broker.destroyService(service)
.then(() => {
if (fs.existsSync(service.__filename)) {
return broker.loadService(service.__filename);
}
});
}
drawGauge(gstart, gstop) {
const gw = this.opts.gaugeWidth;
const p1 = Math.floor(gw * gstart / 100);
const p2 = Math.max(Math.floor(gw * gstop / 100) - p1, 1);
const p3 = Math.max(gw - (p1 + p2), 0);
return [
kleur.grey("["),
kleur.grey(r(".", p1)),
r("■", p2),
kleur.grey(r(".", p3)),
kleur.grey("]")
].join("");
}
drawLine(text) {
this.log(kleur.grey("│ ") + text + kleur.grey(" │"));
}
drawTableBottom() {
this.log(kleur.grey("└" + r("─", this.opts.width - 2) + "┘"));
}
drawGauge(gstart, gstop) {
const gw = this.opts.gaugeWidth;
const p1 = Math.floor(gw * gstart / 100);
const p2 = Math.max(Math.floor(gw * gstop / 100) - p1, 1);
const p3 = Math.max(gw - (p1 + p2), 0);
return [
kleur.grey("["),
kleur.grey(r(".", p1)),
r("■", p2),
kleur.grey(r(".", p3)),
kleur.grey("]")
].join("");
}
return (type, args) => {
const timestamp = new Date().toISOString();
return [this.render(formatter, {
timestamp: kleur.grey(timestamp),
time: kleur.grey(timestamp.substr(11)),
level: this.levelColorStr[type],
nodeID: kleur.grey(bindings.nodeID),
mod: modColorName
}), ...printArgs(args)];
};
}
printSpanTime(spanItem, mainItem, level) {
const span = spanItem.span;
const mainSpan = mainItem.span;
const margin = 2 * 2;
const w = (this.opts.width || 80) - margin;
const gw = this.opts.gaugeWidth || 40;
const time = span.duration == null ? "?" : humanize(span.duration);
const indent = this.getSpanIndent(spanItem);
const caption = this.getCaption(span);
const info = kleur.grey(indent) + this.getAlignedTexts(caption, w - gw - 3 - time.length - 1 - indent.length) + " " + time;
const startTime = span.startTime || mainSpan.startTime;
const finishTime = span.finishTime || mainSpan.finishTime;
let gstart = (startTime - mainSpan.startTime) / (mainSpan.finishTime - mainSpan.startTime) * 100;
let gstop = (finishTime - mainSpan.startTime) / (mainSpan.finishTime - mainSpan.startTime) * 100;
if (_.isNaN(gstart) && _.isNaN(gstop)) {
gstart = 0;
gstop = 100;
}
if (gstop > 100)
gstop = 100;
const c = this.getColor(span);
this.drawLine(c(info + " " + this.drawGauge(gstart, gstop)));