From 183f3b660c7dc53ca0b2f6c8be97d4dc913355b1 Mon Sep 17 00:00:00 2001 From: Ruben Meyer <46384706+rxbnDE@users.noreply.github.com> Date: Wed, 25 Sep 2019 20:21:22 +0200 Subject: [PATCH] log - fallback --- bin/logs/module.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/logs/module.js b/bin/logs/module.js index 6fd2be4..9481c5c 100644 --- a/bin/logs/module.js +++ b/bin/logs/module.js @@ -1,11 +1,3 @@ -/* - * This file is part of the authRxbn eco-system. - * - * (c) Ruben Meyer - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ var methods = {}; let fs = require('fs'); let util = require('util'); @@ -52,12 +44,19 @@ newLine = (prefix, obj) => { // typeof obj == "undefined" // typeof obj == "function" } +}; + +fallback = (fn, ...data) => { + if(data.length == 1) data = data[0]; + + fn.apply(null, data); } // LOG | INFO methods.log = (...data) => { - global['modules'].cli.log.apply(global['modules'].cli, data); + if(global['modules'].cli) global['modules'].cli.log.apply(global['modules'].cli, data); + else fallback(console.log, data); if(data.length == 1) data = data[0]; newLine(" [LOG]", data); @@ -66,7 +65,8 @@ methods.info = methods.log; // WARNING methods.warn = (...data) => { - global['modules'].cli.log.apply(global['modules'].cli, data); + if(global['modules'].cli) global['modules'].cli.log.apply(global['modules'].cli, data); + else fallback(console.warn, data); if(data.length == 1) data = data[0]; newLine(" [WARN]", data); @@ -74,7 +74,8 @@ methods.warn = (...data) => { // ERROR methods.error = (...data) => { - global['modules'].cli.log.apply(global['modules'].cli, data); + if(global['modules'].cli) global['modules'].cli.log.apply(global['modules'].cli, data); + else fallback(console.error, data); if(data.length == 1) data = data[0]; newLine("[ERROR]", data); @@ -84,7 +85,8 @@ methods.err = methods.error; // DEBUG methods.debug = (...data) => { if(global['gds'].debug) { - global['modules'].cli.log.apply(global['modules'].cli, data); + if(global['modules'].cli) global['modules'].cli.log.apply(global['modules'].cli, data); + else fallback(console.log, data); if(data.length == 1) data = data[0]; newLine("[DEBUG]", data);