@@ -32,12 +32,13 @@ export class FeedbackService {
32
32
private logIdx = 0 ;
33
33
private readonly LEVELS = [ 'error' , 'warn' , 'log' , 'info' ] ;
34
34
private readonly LOG_LENGTH = 20 ;
35
- private readonly logs = new Array ( this . LOG_LENGTH ) ;
35
+ private readonly logCircularBuffer = new Array ( this . LOG_LENGTH ) ;
36
36
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
38
38
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 ]
41
42
. reverse ( )
42
43
. filter ( i => ! ! i ) ;
43
44
}
@@ -69,8 +70,14 @@ export class FeedbackService {
69
70
this . LEVELS . forEach ( level => {
70
71
const original = this . options . console [ level ] ;
71
72
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 ;
74
81
if ( this . logIdx === this . LOG_LENGTH ) {
75
82
this . logIdx = 0 ;
76
83
}
0 commit comments