@@ -10,7 +10,8 @@ const IGNORED_MKDIR_ERROR = 'EEXIST';
1010const FILE_DOESNT_EXIST = 'ENOENT' ;
1111const ERRORS = require ( '../constants' ) . ERRORS ;
1212const EVENTS = require ( '../constants' ) . EVENTS ;
13-
13+ const Debug = require ( 'debug' ) ;
14+ const log = Debug ( 'tus-node-server:stores:filestore' ) ;
1415
1516/**
1617 * @fileOverview
@@ -63,23 +64,23 @@ class FileStore extends DataStore {
6364 file_id = this . generateFileName ( req ) ;
6465 }
6566 catch ( generateError ) {
66- console . warn ( '[FileStore] create: check your namingFunction. Error' , generateError ) ;
67+ log ( '[FileStore] create: check your namingFunction. Error' , generateError ) ;
6768 return reject ( ERRORS . FILE_WRITE_ERROR ) ;
6869 }
6970
7071 const file = new File ( file_id , upload_length , upload_defer_length , upload_metadata ) ;
7172
7273 return fs . open ( `${ this . directory } /${ file . id } ` , 'w' , ( err , fd ) => {
7374 if ( err ) {
74- console . warn ( '[FileStore] create: Error' , err ) ;
75+ log ( '[FileStore] create: Error' , err ) ;
7576 return reject ( err ) ;
7677 }
7778
7879 this . configstore . set ( file . id , file ) ;
7980
8081 return fs . close ( fd , ( exception ) => {
8182 if ( exception ) {
82- console . warn ( '[FileStore] create: Error' , exception ) ;
83+ log ( '[FileStore] create: Error' , exception ) ;
8384 return reject ( exception ) ;
8485 }
8586
@@ -114,14 +115,14 @@ class FileStore extends DataStore {
114115 } ) ;
115116
116117 stream . on ( 'error' , ( e ) => {
117- console . warn ( '[FileStore] write: Error' , e ) ;
118+ log ( '[FileStore] write: Error' , e ) ;
118119 reject ( ERRORS . FILE_WRITE_ERROR ) ;
119120 } ) ;
120121
121122 return req . pipe ( stream ) . on ( 'finish' , ( ) => {
122- console . info ( `[FileStore] write: ${ new_offset } bytes written to ${ path } ` ) ;
123+ log ( `[FileStore] write: ${ new_offset } bytes written to ${ path } ` ) ;
123124 offset += new_offset ;
124- console . info ( `[FileStore] write: File is now ${ offset } bytes` ) ;
125+ log ( `[FileStore] write: File is now ${ offset } bytes` ) ;
125126
126127 const config = this . configstore . get ( file_id ) ;
127128 if ( config && parseInt ( config . upload_length , 10 ) === offset ) {
@@ -144,12 +145,12 @@ class FileStore extends DataStore {
144145 const file_path = `${ this . directory } /${ file_id } ` ;
145146 fs . stat ( file_path , ( error , stats ) => {
146147 if ( error && error . code === FILE_DOESNT_EXIST && config ) {
147- console . warn ( `[FileStore] getOffset: No file found at ${ file_path } but db record exists` , config ) ;
148+ log ( `[FileStore] getOffset: No file found at ${ file_path } but db record exists` , config ) ;
148149 return reject ( ERRORS . FILE_NO_LONGER_EXISTS ) ;
149150 }
150151
151152 if ( error && error . code === FILE_DOESNT_EXIST ) {
152- console . warn ( `[FileStore] getOffset: No file found at ${ file_path } ` ) ;
153+ log ( `[FileStore] getOffset: No file found at ${ file_path } ` ) ;
153154 return reject ( ERRORS . FILE_NOT_FOUND ) ;
154155 }
155156
@@ -158,7 +159,7 @@ class FileStore extends DataStore {
158159 }
159160
160161 if ( stats . isDirectory ( ) ) {
161- console . warn ( `[FileStore] getOffset: ${ file_path } is a directory` ) ;
162+ log ( `[FileStore] getOffset: ${ file_path } is a directory` ) ;
162163 return reject ( ERRORS . FILE_NOT_FOUND ) ;
163164 }
164165
0 commit comments