mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 12:36:35 +00:00
Consolidate Discord logger setup
This commit is contained in:
parent
8a544c86c8
commit
10b4c558d3
2 changed files with 9 additions and 7 deletions
|
|
@ -1,3 +1,4 @@
|
|||
const config = require("./config");
|
||||
const { Transport } = require("winston");
|
||||
|
||||
class DiscordWinstonTransport extends Transport {
|
||||
|
|
@ -6,6 +7,13 @@ class DiscordWinstonTransport extends Transport {
|
|||
this._channel = channel;
|
||||
}
|
||||
|
||||
static async addToLogger(client, logger) {
|
||||
await client.login(config.discordToken);
|
||||
const captbaritone = await client.fetchUser(config.CAPTBARITONE_USER_ID);
|
||||
const channel = await captbaritone.createDM();
|
||||
logger.add(new DiscordWinstonTransport(channel));
|
||||
}
|
||||
|
||||
async log(info, callback) {
|
||||
const { message, ...rest } = info;
|
||||
let dataString = null;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Discord = require("discord.js");
|
||||
const config = require("../config");
|
||||
const logger = require("../logger");
|
||||
const DiscordWinstonTransport = require("../DiscordWinstonTransport");
|
||||
|
||||
const CAPTBARITONE_USER_ID = "254029485463044116";
|
||||
|
||||
const client = new Discord.Client();
|
||||
|
||||
function handleStats() {}
|
||||
|
|
@ -79,10 +76,7 @@ client.on("error", e => {
|
|||
});
|
||||
|
||||
async function main() {
|
||||
await client.login(config.discordToken);
|
||||
const captbaritone = await client.fetchUser(CAPTBARITONE_USER_ID);
|
||||
const channel = await captbaritone.createDM();
|
||||
logger.add(new DiscordWinstonTransport(channel));
|
||||
DiscordWinstonTransport.addToLogger(client, logger);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue