Skip to content

Commit

Permalink
Create more advanced logger
Browse files Browse the repository at this point in the history
* Avoid having to use chalk all the time
  • Loading branch information
Julien Lengrand-Lambert authored and Julien Lengrand-Lambert committed Apr 30, 2018
1 parent 1ac4ac3 commit aef29ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/commands/configure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const chalk = require('chalk');

const configure = async() => {
if(await checkConfigExists()){
logger.log(chalk.red.bold('⚠️ Mergify is already configured. Configuring again will override the existing file.'));
logger.warn('⚠️ Mergify is already configured. Configuring again will override the existing file.');
}

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/verify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const verify = async({ userId }) => {
} catch (error) {
spinner.stop();
logger.log('\n🙀 Oh no, could not complete verify. Please review your config');
logger.log(error);
logger.err(error);
process.exit(1);
}
};
Expand Down
5 changes: 2 additions & 3 deletions lib/options/disableCertificateVerification/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { logger } = require('../../utils/logger');
const chalk = require('chalk');
const {logger} = require('../../utils/logger');

const disableCertificateVerification = async() => {
logger.log(chalk.red.bold('⚠️ Disabling certificate verification. This is unsafe and should only be used as last resort.'));
logger.warn('⚠️ Disabling certificate verification. This is unsafe and should only be used as last resort.');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
return;
};
Expand Down
20 changes: 18 additions & 2 deletions lib/utils/logger/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
const chalk = require('chalk');

var Logger = function(){};

Logger.prototype.log = function(...args) {
console.log(...args);
}

Logger.prototype.warn = function(...args) {
console.log(chalk.yellow.bold(...args));
}

Logger.prototype.err = function(...args) {
console.log(chalk.red.bold(...args));
}

module.exports = {
logger: console
};
logger: new Logger()
}

0 comments on commit aef29ed

Please sign in to comment.