File tree 1 file changed +23
-9
lines changed
1 file changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,11 @@ class Consola {
30
30
this . mockTypes ( )
31
31
}
32
32
33
- // Keep serialized version of last message
34
- this . _lastMessage = null
35
- this . _lastMessageTime = null
33
+ // Keep serialized version of last log
34
+ this . _lastLogSerialized = null
35
+ this . _lastLog = null
36
+ this . _lastLogTime = null
37
+ this . _lastLogCount = 0
36
38
}
37
39
38
40
get level ( ) {
@@ -257,20 +259,32 @@ class Consola {
257
259
}
258
260
259
261
// Throttle
260
- const diffTime = this . _lastMessageTime ? logObj . date - this . _lastMessageTime : 0
261
- this . _lastMessageTime = logObj . date
262
+ const diffTime = this . _lastLogTime ? logObj . date - this . _lastLogTime : 0
263
+ this . _lastLogTime = logObj . date
262
264
if ( diffTime < this . _throttle ) {
263
265
try {
264
- const serializedMessage = JSON . stringify ( [ logObj . type , logObj . tag , logObj . args ] )
265
- const isSameMessage = this . _lastMessage === serializedMessage
266
- this . _lastMessage = serializedMessage
267
- if ( isSameMessage ) {
266
+ const serializedLog = JSON . stringify ( [ logObj . type , logObj . tag , logObj . args ] )
267
+ const isSameLog = this . _lastLogSerialized === serializedLog
268
+ this . _lastLogSerialized = serializedLog
269
+ if ( isSameLog ) {
270
+ this . _lastLogCount ++
268
271
return // SPAM!
269
272
}
270
273
} catch ( _ ) {
271
274
// Circular References
272
275
}
273
276
}
277
+ if ( this . _lastLogCount ) {
278
+ this . _log ( {
279
+ ...this . _lastLog ,
280
+ args : [
281
+ ...this . _lastLog . args ,
282
+ `(repeated ${ this . _lastLogCount } times)`
283
+ ]
284
+ } )
285
+ this . _lastLogCount = 0
286
+ }
287
+ this . _lastLog = logObj
274
288
275
289
// Log
276
290
if ( this . _async ) {
You can’t perform that action at this time.
0 commit comments