File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5,14 +5,20 @@ import packageJson from '../../package.json'
55import Crypto from './Crypto'
66import { Share } from '@capacitor/share'
77import { Filesystem , Directory , Encoding } from '@capacitor/filesystem'
8+ import { throttle } from 'throttle-debounce'
89
910export default class Logger {
1011 static log ( ) {
1112 const logMsg = [ new Date ( ) . toISOString ( ) , ...arguments ]
1213
1314 // log to console
1415 DEBUG && console . log ( util . format . apply ( util , logMsg ) )
15- this . messages . push ( util . format . apply ( util , logMsg ) ) // TODO: Use a linked list here to get O(n)
16+ this . messages . push ( util . format . apply ( util , logMsg ) )
17+ throttledTrimLogs ( )
18+ }
19+
20+ static trimLogs ( ) {
21+ this . messages = this . messages . slice ( - 1000 )
1622 }
1723
1824 static async persist ( ) {
@@ -120,4 +126,7 @@ export default class Logger {
120126 }
121127 }
122128}
129+
130+ const throttledTrimLogs = throttle ( 20000 , Logger . trimLogs )
131+
123132Logger . messages = [ ]
You can’t perform that action at this time.
0 commit comments