Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
// Load in chalk for logging | ||
const chalk = require("chalk"); | ||
|
||
let logLevel = 0; | ||
|
||
/* | ||
* TODO: Method to increase indent (use '>' to indicate level) of log messages | ||
*/ | ||
const logDown = () => { | ||
logLevel++; | ||
}; | ||
|
||
/* | ||
* TODO: Method to decrease indent level of log messages | ||
*/ | ||
const logUp = () => { | ||
logLevel--; | ||
if (logLevel < 0) logLevel = 0; | ||
}; | ||
|
||
/* | ||
* TODO: Method to log message, takes string and chalk color (callback essentially) | ||
* This should make use of the indent level as controlled above | ||
*/ | ||
const log = (message, chalkColor) => { | ||
const indent = chalk.grey(`${">".repeat(logLevel)}${logLevel === 0 ? "" : " "}`); | ||
const lines = message.split("\n"); | ||
lines.forEach(line => { | ||
console.log(`${line ? indent : ""}${chalkColor(line)}`); | ||
}); | ||
}; | ||
|
||
// TODO: Use this new logging method for all logging in script | ||
// The aim being that this will make it visually easier to trace how methods are getting called in the stack | ||
|
||
// Export | ||
module.exports = {logDown, logUp, log}; |
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