ShirayukiHaruka - **[Sapphire Logging]**Hello! I'...

[Sapphire Logging] Hello! I've been using Sapphire for a while now, and wondering if there is a way to use custom logger instead sapphire's default one. Context: I've configured winston as my logger and to make my log consistent, I'd like to use my logger instance to log sapphire's one. I've read the source code and kinda have some speculation. - SapphireClient uses ClientLoggerOptions to define the logger field when constructing the client. - ClientLoggerOptions contains level and instance fields, where instance implements ILogger interface. By this, my idea is to create a custom logger class that implements the said interface, then probably make it as singleton so it uses the same logger instance every time. My question is, is this the preferred way or there is a better approach for this? Thanks!
5 Replies
Sawako
Sawako3y ago
as you say is the best way Create the class that implements the Sapphire Logger interface and in the methods use winston
Favna
Favna3y ago
Should also note that if you run your bot in pm2 or docker in production and your only use for Winston is to log to a file that those services already log to files and you're double logging by using Winston. But yes custom loggers always have to extend the built in logger class otherwise they won't log internal messages
Favna
Favna3y ago
Also if you're a real gigachad you make it an npm package and PR it to https://github.com/sapphiredev/awesome-sapphire because you're far from the first person who wants a Winston based logger
GitHub
GitHub - sapphiredev/awesome-sapphire: Manually curated collection ...
Manually curated collection of resources, plugins, utilities, and other assortments for the Sapphire Community projects. - GitHub - sapphiredev/awesome-sapphire: Manually curated collection of reso...
白雪はるか
白雪はるかOP3y ago
Nice, thanks! I'll proceed with my current way. By the way, is there any convention I should follow if I were to write the plugin? I saw this repo https://github.com/sapphiredev/sapphire-template and wondering if I should use this template or it's up to repo owner on how to structure,document,and write the code.
GitHub
GitHub - sapphiredev/sapphire-template: Template to be used for Sap...
Template to be used for Sapphire Project repositories - GitHub - sapphiredev/sapphire-template: Template to be used for Sapphire Project repositories
Favna
Favna3y ago
other than the /register convention that is used for other plugins (see https://github.com/sapphiredev/plugins ) not really
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.
Want results from more Discord servers?
Add your server