@krauters/debuggable
Version:
A TypeScript utility that automatically adds detailed debug logs before and after method calls in classes, simplifying the tracking of execution flow and troubleshooting.
29 lines • 867 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DurationTracker = void 0;
class DurationTracker {
startTimes;
constructor(log) {
log ??= console;
log.debug(`Initializing [${this.constructor.name}]`);
this.startTimes = {};
}
end(key) {
const startTime = this.startTimes[key];
if (startTime !== undefined) {
const duration = Date.now() - startTime;
delete this.startTimes[key];
return duration;
}
}
start(key, withSeed = true) {
if (withSeed) {
const seed = (Math.random() + 1).toString(36).substring(7);
key += `-${seed}`;
}
this.startTimes[key] = Date.now();
return key;
}
}
exports.DurationTracker = DurationTracker;
//# sourceMappingURL=duration-tracker.js.map