Skip to content

Commit

Permalink
moved tag from message to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
AllBitsEqual committed Feb 13, 2021
1 parent b7e0ee9 commit bf20870
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const logLevels = {
modinfo: 5,
debug: 6,
}
const logger = winston.createLogger({
levels: logLevels,
transports: [new winston.transports.Console({ colorize: true, timestamp: true })],
format: winston.format.combine(
winston.format.colorize(),
winston.format.padLevels({ levels: logLevels }),
winston.format.timestamp(),
winston.format.printf(info => `${info.timestamp} ${info.level}:${info.message}`),
),
level: 'debug',
})
const logger = tag =>
winston.createLogger({
levels: logLevels,
transports: [new winston.transports.Console({ colorize: true, timestamp: true })],
format: winston.format.combine(
winston.format.colorize(),
winston.format.padLevels({ levels: logLevels }),
winston.format.timestamp(),
winston.format.printf(info => `${info.timestamp} ${info.level}: ${tag}${info.message}`),
),
level: 'debug',
})

winston.addColors({
error: 'red',
warn: 'yellow',
Expand All @@ -50,18 +52,18 @@ const createBot = initialConfig => {
// Define the bot
const bot = {
client: new discord.Client(),
log: logger,
log: logger(initialConfig.tag || `[Bot ${initialConfig.index}]`),
commands: new discord.Collection(),
}

/*
* Define all the core functions for the bot lifecycle
*/
bot.loadConfig = function loadConfig(config, tag, callback) {
this.log.info(`${tag} Loading config...`)
this.log.info(`Loading config...`)
try {
if (!config || !has(config, 'token')) {
throw Error(`${tag} Config or token are missing.`)
throw Error(`Config or token are missing.`)
}
this.config = {
...configSchema,
Expand All @@ -83,21 +85,19 @@ const createBot = initialConfig => {

// Load config, load modules, and login
this.loadConfig(config, tag, () => {
this.log.info(`${tag} Loading commands...`)
this.log.info(`Loading commands...`)
Object.keys(botCommands).forEach(key => {
this.commands.set(botCommands[key].name, botCommands[key])
})
this.log.info(`${tag} Connecting...`)
this.log.info(`Connecting...`)
this.client.login(this.config.token)
})
}

// Fired on successful login
bot.onConnect = async function onConnect() {
this.log.info(
chalk.cyan(
`${this.config.tag} Logged in as: ${this.client.user.tag} (id: ${this.client.user.id})`,
),
chalk.cyan(`Logged in as: ${this.client.user.tag} (id: ${this.client.user.id})`),
)
}

Expand Down

0 comments on commit bf20870

Please sign in to comment.