the-philociraptor
the-philociraptor
SIASapphire - Imagine a framework
Created by the-philociraptor on 5/21/2024 in #sapphire-support
Export Commands and Parameters
Thank you!
5 replies
SIASapphire - Imagine a framework
Created by the-philociraptor on 5/15/2024 in #sapphire-support
Autocomplete - option.match is not a function
Odd. Thanks. I've not gotten a chance to try it yet because I've properly pissed off typescript, but I'll go ahead and marks this as solved.
5 replies
SIASapphire - Imagine a framework
Created by WeeskyBDW on 5/6/2024 in #sapphire-support
Custom logger transport
Yeah, that'd be great. Just wanted to put forward a simple solution in case it could help you. 🙂
24 replies
SIASapphire - Imagine a framework
Created by WeeskyBDW on 5/6/2024 in #sapphire-support
Custom logger transport
It's really silly to force such a basic logger. I didn't feel like making a plugin, but this might help you @WeeskyBDW:
import './lib/setup';

import { Logtail } from '@logtail/node';
import { LogLevel, SapphireClient } from '@sapphire/framework';
import { ClientOptions, GatewayIntentBits, Partials } from 'discord.js';

const logtail = new Logtail(LOGTAILTOKEN);

class ExtendedSapphireClient extends SapphireClient {
hmr: { enabled: boolean };
log: {
info: (message: any) => Promise<void>;
error: (message: any) => Promise<void>;
warn: (message: any) => Promise<void>;
fatal: (message: any) => Promise<void>;
debug: (message: any) => Promise<void>;
flush: () => Promise<void>;
};

constructor(options: ClientOptions) {
super(options);
this.hmr = {
enabled: process.env.NODE_ENV === 'development'
};
this.log = {
info: async (message: string) => {
await logtail.info(message);
this.logger.info(message);
},
error: async (message: string) => {
await logtail.error(message);
this.logger.error(message);
},
fatal: async (message: string) => {
await logtail.error(message);
this.logger.fatal(message);
},
warn: async (message: string) => {
await logtail.warn(message);
this.logger.warn(message);
},
debug: async (message: string) => {
await logtail.debug(message);
this.logger.debug(message);
},
flush: async () => {
await logtail.flush();
}
};
}
}

const client = new ExtendedSapphireClient({
logger: {
level: LogLevel.Debug
},
shards: 'auto',
intents: [
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel]
});

const main = async () => {
try {
await client.log.info('Logging in');
await client.login(TOKEN);
await client.log.info('Logged in');
} catch (error) {
await client.log.fatal(error);
await client.destroy();
await client.log.flush();
process.exit(1);
}
};

void main();
import './lib/setup';

import { Logtail } from '@logtail/node';
import { LogLevel, SapphireClient } from '@sapphire/framework';
import { ClientOptions, GatewayIntentBits, Partials } from 'discord.js';

const logtail = new Logtail(LOGTAILTOKEN);

class ExtendedSapphireClient extends SapphireClient {
hmr: { enabled: boolean };
log: {
info: (message: any) => Promise<void>;
error: (message: any) => Promise<void>;
warn: (message: any) => Promise<void>;
fatal: (message: any) => Promise<void>;
debug: (message: any) => Promise<void>;
flush: () => Promise<void>;
};

constructor(options: ClientOptions) {
super(options);
this.hmr = {
enabled: process.env.NODE_ENV === 'development'
};
this.log = {
info: async (message: string) => {
await logtail.info(message);
this.logger.info(message);
},
error: async (message: string) => {
await logtail.error(message);
this.logger.error(message);
},
fatal: async (message: string) => {
await logtail.error(message);
this.logger.fatal(message);
},
warn: async (message: string) => {
await logtail.warn(message);
this.logger.warn(message);
},
debug: async (message: string) => {
await logtail.debug(message);
this.logger.debug(message);
},
flush: async () => {
await logtail.flush();
}
};
}
}

const client = new ExtendedSapphireClient({
logger: {
level: LogLevel.Debug
},
shards: 'auto',
intents: [
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel]
});

const main = async () => {
try {
await client.log.info('Logging in');
await client.login(TOKEN);
await client.log.info('Logged in');
} catch (error) {
await client.log.fatal(error);
await client.destroy();
await client.log.flush();
process.exit(1);
}
};

void main();
Basically, overriding the sapphire client with a custom client and then making my own method in the class of that custom client to use whatever log lib while keeping the fruity logs. This is a lazy way to do it, but typescript is happy so I am happy.
24 replies