spinny logs

v2
Kit Kasune 2 years ago
parent 31d5741707
commit 3b3d64cf62
  1. 13
      bot.js
  2. 5
      src/util/log/log.js
  3. 12
      src/util/log/ora.js
  4. 7
      src/util/misc/wait.js

@ -1,7 +1,13 @@
const logger = require('./src/util/log/log');
const ora = require('./src/util/log/ora');
const wait = require('./src/util/misc/wait');
const chalk = require('chalk');
const client = {test: 'e', config: {logLevel: 1}};
const loggers = logger(client);
const log = loggers.log;
log();
log("Hello World!")
log("Hello in blue", {color: 'blue'});
@ -15,4 +21,9 @@ log('regular line');
log('a custom fancy pink color', {color: '#ff00ff', sourceColor: '#660066'});*/
loggers.warn("A warning appears!");
loggers.error("Something bad happened!");
loggers.success("Something good happened!");
loggers.success("Something good happened!");
const r = async () => {
await ora(chalk.yellowBright("Waiting for a slow connection..."), wait(2000), () => loggers.success("Connected!", 0, true));
log('after thingy');
};
r();

@ -13,8 +13,9 @@ let defaultOptions = {
suffix: " >> "
};
const tlog = (client) => (message = "Test Log", options = {}, newLine = false, spacer = false) => {
const tlog = (client) => (message = "Test Log", options = {}, prenl = false, postnl = false) => {
let opt = {};
if (typeof options !== 'object') {options = {};}
opt.color = options.color || defaultOptions.color;
opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level;
opt.suffix = typeof options.suffix === 'string' ? options.suffix : defaultOptions.suffix;
@ -25,7 +26,7 @@ const tlog = (client) => (message = "Test Log", options = {}, newLine = false, s
client.config.logLevel = getLevel(client.config.logLevel);
if (client.config.logLevel < opt.level) {return;}
}
console.log(`${spacer ? '\n' : ''}${(opt.sourceColor.startsWith('#') ? chalk.hex(opt.sourceColor) : chalk[opt.sourceColor])(`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : (opt.color.startsWith('#') ? chalk.hex(opt.color) : chalk[opt.color])(message)}${newLine ? '\n' : ''}`);
console.log(`${prenl ? '\n' : ''}${(opt.sourceColor.startsWith('#') ? chalk.hex(opt.sourceColor) : chalk[opt.sourceColor])(`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : (opt.color.startsWith('#') ? chalk.hex(opt.color) : chalk[opt.color])(message)}${postnl ? '\n' : ''}`);
};
module.exports = (client) => {

@ -0,0 +1,12 @@
const ora = require('ora');
module.exports = async (text, promise, callback) => {
let spin = ora(text).start();
await promise
.catch(e => callback(spin, e))
.then((...args) => {
spin.stop();
spin.clear();
callback(spin, args);
});
};

@ -0,0 +1,7 @@
module.exports = (time) => {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(null);
}, time);
});
};
Loading…
Cancel
Save