custom log types

v2
Kit Kasune 2 years ago
parent d469ed3969
commit 31d5741707
  1. 10
      bot.js
  2. 10
      src/util/log/log.js
  3. 20
      src/util/log/types.js

@ -1,14 +1,18 @@
const logger = require('./src/util/log/log'); const logger = require('./src/util/log/log');
const client = {test: 'e', config: {logLevel: 1}}; const client = {test: 'e', config: {logLevel: 1}};
const log = logger(client); const loggers = logger(client);
const log = loggers.log;
log(); log();
log("Hello World!") log("Hello World!")
log("Hello in blue", {color: 'blue'}); 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');
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');
log('a custom fancy pink color', {color: '#ff00ff', sourceColor: '#660066'}); 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!");

@ -1,6 +1,7 @@
const chalk = require('chalk'); const chalk = require('chalk');
const getLevel = require('./getlevel'); const getLevel = require('./getlevel');
const types = require('./types');
const config = require('../../json/config.json'); const config = require('../../json/config.json');
@ -12,8 +13,7 @@ let defaultOptions = {
suffix: " >> " suffix: " >> "
}; };
module.exports = (client) => { const tlog = (client) => (message = "Test Log", options = {}, newLine = false, spacer = false) => {
return (message = "Test Log", options = {}, newLine = false, spacer = false) => {
let opt = {}; let opt = {};
opt.color = options.color || defaultOptions.color; opt.color = options.color || defaultOptions.color;
opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level; opt.level = ['string', 'number'].includes(typeof options.level) ? options.level : defaultOptions.level;
@ -27,4 +27,10 @@ module.exports = (client) => {
} }
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(`${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' : ''}`);
}; };
module.exports = (client) => {
return {
log: tlog(client),
...types(tlog(client))
};
}; };

@ -0,0 +1,20 @@
module.exports = (log) => { return {
error: (message, options, newLine, spacer) => log(message, {
color: 'redBright',
source: 'err!',
sourceColor: 'red',
level: 0
}, newLine, spacer),
warn: (message, options, newLine, spacer) => log(message, {
color: 'yellowBright',
source: 'warn',
sourceColor: 'yellow',
level: 1
}, newLine, spacer),
success: (message, options, newLine, spacer) => log(message, {
color: 'greenBright',
source: 'proc' || options && options.source,
sourceColor: 'green',
level: options && typeof options.level !== 'undefined' ? options.level : 0
}, newLine, spacer)
}};
Loading…
Cancel
Save