Skip to content

Commit

Permalink
logger: define colorMap outside colorize()
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Oct 30, 2022
1 parent 81f4638 commit bc46b13
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,31 @@ export function error(obj: Error) {
}
}

let colorMap = {
'[E]': 'red', // ERROR
'[W]': 'yellow', // WARNING
'[?]': 'yellow', // MISSING
'[S]': 'green', // SUCCESS
'[i]': 'blue', // INFO
'[+]': 'green', // ADDED
'[-]': 'red', // REMOVED
'[C]': 'cyan', // CHANGED
'[U]': 'grey', // UNCHANGED
'[=]': 'grey', // EQUAL
'[/]': 'grey', // SKIPPED
'[V]': 'magenta', // VERBOSE
'[D]': 'magenta', // DEBUG
'[T]': 'magenta', // TO-DO
'[TODO]': 'magenta', // TO-DO
};

/**
* Colors the messages by searching for specific indicator strings
*
* @param {string} msg
* @returns {string}
*/
export function colorize(msg: item) {
let colorMap = {
'[E]': 'red', // ERROR
'[W]': 'yellow', // WARNING
'[?]': 'yellow', // MISSING
'[S]': 'green', // SUCCESS
'[i]': 'blue', // INFO
'[+]': 'green', // ADDED
'[-]': 'red', // REMOVED
'[C]': 'cyan', // CHANGED
'[U]': 'grey', // UNCHANGED
'[=]': 'grey', // EQUAL
'[/]': 'grey', // SKIPPED
'[V]': 'magenta', // VERBOSE
'[D]': 'magenta', // DEBUG
'[T]': 'magenta', // TO-DO
'[TODO]': 'magenta', // TO-DO
};

for (let [code, color] of Object.entries(colorMap)) {
if (msg && msg.indexOf && msg.startsWith(code)) {
return chalk[color](msg);
Expand Down

0 comments on commit bc46b13

Please sign in to comment.