diff --git a/bot.js b/bot.js index f8231ac..e119d6b 100644 --- a/bot.js +++ b/bot.js @@ -7,7 +7,8 @@ log("Hello in blue", {color: 'blue'}); log('A strange warning appears!', {color: 'yellowBright', source: 'warn', sourceColor: 'yellow'}); log('Extra line spacing before', {}, false, true); log('regular line'); +client.config.logLevel = 0; log('extra line spacing after', {}, true); log('regular line'); log('both line spaces', {}, true, true); -log('regular line'); +log('regular line'); \ No newline at end of file diff --git a/src/util/log/getlevel.js b/src/util/log/getlevel.js index a204f1a..0f4b6a5 100644 --- a/src/util/log/getlevel.js +++ b/src/util/log/getlevel.js @@ -1,5 +1,5 @@ const config = require('../../json/config.json'); -const levels = require('../ts/log/levels.json'); +const levels = require('./levels.json'); const validStrings = Object.keys(levels); const getLevel = (level) => { diff --git a/src/util/log/log.js b/src/util/log/log.js index cb917b4..5c2d8b0 100644 --- a/src/util/log/log.js +++ b/src/util/log/log.js @@ -1,19 +1,30 @@ const chalk = require('chalk'); +const getLevel = require('./getlevel'); + +const config = require('../../json/config.json'); + let defaultOptions = { color: "white", source: "USER", sourceColor: "gray", - level: 1, + level: typeof config.log.defaultLevel === 'number' ? config.log.defaultLevel : 1, suffix: " >> " }; -module.exports = (client) => (message = "Test Log", options = {}, newLine = false, spacer = false) => { - let opt = {}; - 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; - opt.source = options.source || defaultOptions.source; - opt.sourceColor = options.sourceColor || defaultOptions.sourceColor; - console.log(`${spacer ? '\n' : ''}${chalk[opt.sourceColor](`[${opt.source.toUpperCase()}]`)}${opt.suffix}${options.nc || options.noColor ? message : chalk[opt.color](message)}${newLine ? '\n' : ''}`); +module.exports = (client) => { + return (message = "Test Log", options = {}, newLine = false, spacer = false) => { + let opt = {}; + 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; + opt.source = options.source || defaultOptions.source; + 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' : ''}`); + }; }; \ No newline at end of file