Commit 70b209ce authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] add quiet flag

parent 74d98bdd
/* eslint-disable no-console */
const logSymbols = require('log-symbols');
const timestamp = require('time-stamp');
const chalk = require('chalk');
const notifier = require('node-notifier');
const path = require('path');
const browserSync = require('browser-sync');
const {argv} = require('yargs');
/**
* Logging-Module for the SGC
......@@ -12,53 +15,65 @@ module.exports = class Logger {
/**
* Logs an info message
*
*
* @param {String} _message The message to log
*/
static info(_message) {
console.log(Logger._getTimestamp(), logSymbols.info, chalk.blue(_message));
static info(_message, _force = false) {
if ((argv.q || argv.quiet) && !_force) {
return;
}
console.log(Logger.getTimestamp(), logSymbols.info, chalk.blue(_message));
}
/**
* Logs a warning message
*
*
* @param {String} _message The message to log
*/
static warning(_message) {
console.log(Logger._getTimestamp(), logSymbols.warning, chalk.yellow(_message));
static warning(_message, _force = false) {
if ((argv.q || argv.quiet) && !_force) {
return;
}
console.log(Logger.getTimestamp(), logSymbols.warning, chalk.yellow(_message));
}
/**
* Logs an error message
*
*
* @param {String} _message The message to log
*/
static error(_message) {
console.log(Logger._getTimestamp(), logSymbols.error, chalk.red(_message));
static error(_message, _force) {
if ((argv.q || argv.quiet) && !_force) {
return;
}
console.log(Logger.getTimestamp(), logSymbols.error, chalk.red(_message));
Logger.displayNotification('Your task failed!', _message);
}
/**
* Logs a success message
*
*
* @param {String} _message The message to log
*/
static success(_message) {
console.log(Logger._getTimestamp(), logSymbols.success, chalk.green(_message));
static success(_message, _force = false) {
if ((argv.q || argv.quiet) && !_force) {
return;
}
console.log(Logger.getTimestamp(), logSymbols.success, chalk.green(_message));
}
/**
* Generates the output for the current timestamp
*
*
* @private
*/
static _getTimestamp() {
static getTimestamp() {
return chalk.dim(chalk.white(`[${timestamp('HH:mm:ss')}]`));
}
/**
* Displays a desktop notification
*
*
* @param {String} _title The title for your notification
* @param {String} _message The message for your notification
*/
......@@ -76,10 +91,10 @@ module.exports = class Logger {
/**
* Displays a BS notification
*
*
* @param {String} _message The message to display
*/
static displayBrowserSyncNotification(_message) {
browserSync.notify(`<b>SGC:</b> ${_message}`);
}
}
};
......@@ -35,7 +35,7 @@ class Run {
}
static processEnd() {
logger.info(`SGC finished after ${getElapsed(hirestime.S)}s`);
logger.info(`SGC finished after ${getElapsed(hirestime.S)}s`, true);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment