-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented interface for centralized logging behaviour * Added success and error logging for all commands * Added logging for download progress
- Loading branch information
1 parent
1ce10ef
commit 377590d
Showing
5 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { info } = require('./logger'); | ||
|
||
const PERCENTAGE_STEP_SIZE = 5; | ||
|
||
class ProgressTransformOptions { | ||
constructor (streamLength) { | ||
this.lastLogged = 0; | ||
this.progress = 0; | ||
this.length = streamLength; | ||
} | ||
|
||
transform (chunk, controller) { | ||
this.progress += chunk.length; | ||
controller.enqueue(chunk); | ||
this.logProgress(); | ||
} | ||
|
||
logProgress () { | ||
const percentage = Math.trunc(this.progress * 100 / this.length); | ||
if (percentage >= this.lastLogged + PERCENTAGE_STEP_SIZE) { | ||
info(`Progress: ${percentage}%`); | ||
this.lastLogged = percentage; | ||
} | ||
} | ||
} | ||
|
||
class ProgressTransformStream extends TransformStream { | ||
constructor (streamLength) { | ||
super(new ProgressTransformOptions(streamLength)); | ||
} | ||
} | ||
|
||
module.exports = ProgressTransformStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const logger = require('./logger'); | ||
const ProgressTransformStream = require('./ProgressTransformStream'); | ||
|
||
function info (msg) { | ||
logger.info(msg); | ||
} | ||
|
||
function error (error) { | ||
logger.error(error); | ||
} | ||
|
||
module.exports = { | ||
info, | ||
error, | ||
ProgressTransformStream, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const LOGGER = { | ||
info: msg => console.info(msg), | ||
error: err => console.error(err), | ||
}; | ||
|
||
module.exports = LOGGER; |