v2
Kit Kasune 2 years ago
parent 1dadc3f888
commit a74538f085
  1. 3
      bot.js
  2. 2
      src/util/log/getlevel.js
  3. 29
      src/util/log/log.js

@ -7,7 +7,8 @@ log("Hello in blue", {color: 'blue'});
log('A strange warning appears!', {color: 'yellowBright', source: 'warn', sourceColor: 'yellow'}); log('A strange warning appears!', {color: 'yellowBright', source: 'warn', sourceColor: 'yellow'});
log('Extra line spacing before', {}, false, true); log('Extra line spacing before', {}, false, true);
log('regular line'); log('regular line');
client.config.logLevel = 0;
log('extra line spacing after', {}, true); log('extra line spacing after', {}, true);
log('regular line'); log('regular line');
log('both line spaces', {}, true, true); log('both line spaces', {}, true, true);
log('regular line'); log('regular line');

@ -1,5 +1,5 @@
const config = require('../../json/config.json'); const config = require('../../json/config.json');
const levels = require('../ts/log/levels.json'); const levels = require('./levels.json');
const validStrings = Object.keys(levels); const validStrings = Object.keys(levels);
const getLevel = (level) => { const getLevel = (level) => {

@ -1,19 +1,30 @@
const chalk = require('chalk'); const chalk = require('chalk');
const getLevel = require('./getlevel');
const config = require('../../json/config.json');
let defaultOptions = { let defaultOptions = {
color: "white", color: "white",
source: "USER", source: "USER",
sourceColor: "gray", sourceColor: "gray",
level: 1, level: typeof config.log.defaultLevel === 'number' ? config.log.defaultLevel : 1,
suffix: " >> " suffix: " >> "
}; };
module.exports = (client) => (message = "Test Log", options = {}, newLine = false, spacer = false) => { module.exports = (client) => {
let opt = {}; return (message = "Test Log", options = {}, newLine = false, spacer = false) => {
opt.color = options.color || defaultOptions.color; let opt = {};
opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level; opt.color = options.color || defaultOptions.color;
opt.suffix = typeof options.suffix === 'string' ? options.suffix : defaultOptions.suffix; opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level;
opt.source = options.source || defaultOptions.source; opt.suffix = typeof options.suffix === 'string' ? options.suffix : defaultOptions.suffix;
opt.sourceColor = options.sourceColor || defaultOptions.sourceColor; opt.source = options.source || defaultOptions.source;
console.log(`${spacer ? '\n' : ''}${chalk[opt.sourceColor](`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : chalk[opt.color](message)}${newLine ? '\n' : ''}`); opt.sourceColor = options.sourceColor || defaultOptions.sourceColor;
try {if (client.config.logLevel < opt.level) {return;}}
catch {
client.config.logLevel = getLevel(client.config.logLevel);
if (client.config.logLevel < opt.level) {return;}
}
console.log(`${spacer ? '\n' : ''}${chalk[opt.sourceColor](`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : chalk[opt.color](message)}${newLine ? '\n' : ''}`);
};
}; };
Loading…
Cancel
Save