@@ -73,6 +73,10 @@ if (!util.isBrowser()) {
7373 Logger . prototype . export = function ( ) {
7474 return this . _fs . readFileSync ( this . dbname , 'utf8' )
7575 }
76+
77+ Logger . prototype . clear = function ( ) {
78+
79+ }
7680} else {
7781 Logger . prototype . echo = function ( data ) {
7882 if ( this . db !== null ) {
@@ -86,44 +90,61 @@ if (!util.isBrowser()) {
8690 }
8791
8892 Logger . prototype . all = function ( ) {
89- const tx = this . db . transaction ( this . dbname , 'readonly' )
90- const store = tx . objectStore ( this . dbname )
91- return new Promise ( function ( resolve , reject ) {
92- const req = store . getAll ( )
93- req . addEventListener ( 'success' , function ( e ) {
94- resolve ( req . result )
95- } )
96- req . addEventListener ( 'error' , function ( e ) {
97- reject ( false )
93+ if ( this . db !== null ) {
94+ const tx = this . db . transaction ( this . dbname , 'readonly' )
95+ const store = tx . objectStore ( this . dbname )
96+ return new Promise ( function ( resolve , reject ) {
97+ const req = store . getAll ( )
98+ req . addEventListener ( 'success' , function ( e ) {
99+ resolve ( req . result )
100+ } )
101+ req . addEventListener ( 'error' , function ( e ) {
102+ reject ( false )
103+ } )
98104 } )
99- } )
105+ }
106+
100107 }
101108
102109 Logger . prototype . len = function ( ) {
103- const tx = this . db . transaction ( this . dbname , 'readonly' )
104- const store = tx . objectStore ( this . dbname )
105- return new Promise ( function ( resolve , reject ) {
106- const req = store . count ( )
107- req . addEventListener ( 'success' , function ( e ) {
108- resolve ( req . result )
109- } )
110- req . addEventListener ( 'error' , function ( e ) {
111- reject ( false )
110+ if ( this . db !== null ) {
111+ const tx = this . db . transaction ( this . dbname , 'readonly' )
112+ const store = tx . objectStore ( this . dbname )
113+ return new Promise ( function ( resolve , reject ) {
114+ const req = store . count ( )
115+ req . addEventListener ( 'success' , function ( e ) {
116+ resolve ( req . result )
117+ } )
118+ req . addEventListener ( 'error' , function ( e ) {
119+ reject ( false )
120+ } )
112121 } )
113- } )
122+ }
123+
114124 }
115125
116126 Logger . prototype . export = async function ( ) {
117- const r = await this . all ( )
118- let text = ''
119- r . forEach ( ( value , index ) => {
120- text += `${ JSON . stringify ( {
127+ if ( this . db !== null ) {
128+ const r = await this . all ( )
129+ let text = ''
130+ r . forEach ( ( value , index ) => {
131+ text += `${ JSON . stringify ( {
121132 t : value . t ,
122133 frame : value . frame ,
123134 } ) } \n`
124- } )
125- util . download ( this . dbname , text )
126- return text
135+ } )
136+ util . download ( this . dbname , text )
137+ return text
138+ }
139+
140+ }
141+
142+ Logger . prototype . clear = function ( ) {
143+ if ( this . db !== null ) {
144+ const tx = this . db . transaction ( this . dbname , 'readwrite' )
145+ const store = tx . objectStore ( this . dbname )
146+ store . clear ( )
147+ }
127148 }
128149}
129150
0 commit comments