Custom logger transport

Hello is they a way to set custom logger transport (like what winston allow to do) with sapphire logger (plugin logger) ? I saw other ppls also want similar things/support with winston
16 Replies
Favna
Favna•8mo ago
there isn't, you'll have to make your own plugin. If you do, please let us know through a PR to the "awesome-sapphire" repo because as you noted other people have asked before, but we never hear back from them afterwards.
WeeskyBDW
WeeskyBDWOP•8mo ago
i can do it but i can't ensure i can maintain it (because i have the worst time management of all time)
Favna
Favna•8mo ago
dont we all it's still better than nothing tbh
WeeskyBDW
WeeskyBDWOP•8mo ago
the question i have rn about that is : how should ppls being able to add transport ? directly interact with winston ? custom way with sapphire ?
Favna
Favna•8mo ago
I'd say make a plugin along the lines of sapphire-logger-winston then let them put in their own winston options? I have never used winston so I can't really say
WeeskyBDW
WeeskyBDWOP•8mo ago
ok ok thx
WeeskyBDW
WeeskyBDWOP•8mo ago
GitHub
GitHub - sapphiredev/sapphire-template: Template to be used for Sap...
Template to be used for Sapphire Project repositories - sapphiredev/sapphire-template
Favna
Favna•8mo ago
GitHub
GitHub - sapphiredev/examples: Various examples of setting up your ...
Various examples of setting up your bot with the Sapphire Framework - sapphiredev/examples
WeeskyBDW
WeeskyBDWOP•8mo ago
i dont see plugin example but more framework use exampels examples*
Favna
Favna•8mo ago
oh yeah no there aren't any "examples" in that form for plugins, for that ref er to https://github.com/sapphiredev/plugins (you can drop the mono repo structure)
GitHub
GitHub - sapphiredev/plugins: Plugins for the Sapphire Framework
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
WeeskyBDW
WeeskyBDWOP•8mo ago
thx and last question: where can i ask opinions about things related to how to organise that plugin ? like what should i made publicy available and how
Favna
Favna•8mo ago
#Coding
WeeskyBDW
WeeskyBDWOP•8mo ago
thx
the-philociraptor
the-philociraptor•8mo ago
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.
WeeskyBDW
WeeskyBDWOP•8mo ago
Thx, doing a plugin would more be to allow anyone to use wilston logging librairie easly but for sure anyone can implement it manually
the-philociraptor
the-philociraptor•8mo ago
Yeah, that'd be great. Just wanted to put forward a simple solution in case it could help you. 🙂
Want results from more Discord servers?
Add your server