Skip to content

Commit e3aec1e

Browse files
authored
feat(medic#8136): Add current timestamp into feedback document logs
1 parent 08966af commit e3aec1e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

webapp/src/ts/services/feedback.service.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ export class FeedbackService {
3232
private logIdx = 0;
3333
private readonly LEVELS = ['error', 'warn', 'log', 'info'];
3434
private readonly LOG_LENGTH = 20;
35-
private readonly logs = new Array(this.LOG_LENGTH);
35+
private readonly logCircularBuffer = new Array(this.LOG_LENGTH);
3636

37-
// Flips and reverses log into a clean latest first array for logging out
37+
// converts the logCircularBuffer into an ordered array of log events
3838
private getLog() {
39-
// [oldest + newest] -> reversed -> filter empty
40-
return (this.logs.slice(this.logIdx, this.LOG_LENGTH).concat(this.logs.slice(0, this.logIdx)))
39+
const olderLogEvents = this.logCircularBuffer.slice(this.logIdx, this.LOG_LENGTH);
40+
const newerLogEvents = this.logCircularBuffer.slice(0, this.logIdx);
41+
return [...olderLogEvents, ...newerLogEvents]
4142
.reverse()
4243
.filter(i => !!i);
4344
}
@@ -69,8 +70,14 @@ export class FeedbackService {
6970
this.LEVELS.forEach(level => {
7071
const original = this.options.console[level];
7172
this.options.console[level] = (...args) => {
72-
// push the error onto the stack
73-
this.logs[this.logIdx++] = { level, arguments: JSON.stringify(args, getCircularReplacer()) };
73+
const logEvent = {
74+
level,
75+
arguments: JSON.stringify(args, getCircularReplacer()),
76+
time: new Date().toISOString(),
77+
};
78+
79+
// push the log event onto the circular buffer
80+
this.logCircularBuffer[this.logIdx++] = logEvent;
7481
if (this.logIdx === this.LOG_LENGTH) {
7582
this.logIdx = 0;
7683
}

0 commit comments

Comments
 (0)