-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathlogger.js
More file actions
25 lines (23 loc) · 896 Bytes
/
logger.js
File metadata and controls
25 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const chalk = require('chalk');
let isDebugModeEnabled = false;
const logAdapter = (msg, force) => (isDebugModeEnabled || force) && console.log(msg);
module.exports = {
getText: e => {
try {
if (typeof e === 'object') {
const stringifiedError = JSON.stringify(e);
return stringifiedError === '{}' ? e : stringifiedError;
} else {
return e;
}
} catch (e) {
return `COULD NOT PARSE ERROR ${e}`;
}
},
log: (...args) => logAdapter(chalk.blue.apply(chalk, args)),
info: (...args) => logAdapter(chalk.green.apply(chalk, args)),
warn: (...args) => logAdapter(chalk.yellow.apply(chalk, args)),
error: (...args) => logAdapter(chalk.red.apply(chalk, args), true),
fun: (...args) => logAdapter(chalk.keyword('purple').apply(chalk, args), true),
setDebugModeEnabled: (debugModeEnabled) => isDebugModeEnabled = debugModeEnabled
};