Replacing Logger

Is there any way to replace the logger with custom on or editing it's style at least
Solution:
we have @sapphire/plugin-logger, or if that style doesnt suite you then you'll have to make a similar plugin yourself.
Jump to solution
27 Replies
Solution
Favna
Favna14mo ago
we have @sapphire/plugin-logger, or if that style doesnt suite you then you'll have to make a similar plugin yourself.
Spinel
Spinel14mo ago
@sapphire/plugin-logger
Plugin for @sapphire/framework to have pretty console output ❯ Author: sapphiredev ❯ Maintainers: favna, kyranet, and vladfrangu ❯ Latest version: 3.0.6 ❯ License: MIT ❯ Date Created: <t:1608819495:d> ❯ Date Modified: <t:1697502716:d> Dependencies: @sapphire/timestamp and colorette
Sayed
SayedOP14mo ago
Will that replace the messages of loading commands listeners ... ?
Favna
Favna14mo ago
Note to self: add screenshot of how it looks to the readme Yes, all logs from sapphire and all logs that were logged through container.logger.<level>
Sayed
SayedOP14mo ago
Ok but If I made custom one how to integrate it I hope so 😀 People before notion:
Sayed
SayedOP14mo ago
@Favna Now I created custom logger and replaced it with the logger of the container but the mesages while running bot not like my own so how to replace it too
No description
No description
Favna
Favna14mo ago
huh idgi
Sayed
SayedOP14mo ago
You said I must make custom logger if the style doesn't suite my needs I did like you said but the used logger here isn't like my custom logger
No description
Favna
Favna14mo ago
did you actually register it
Sayed
SayedOP14mo ago
How to register it?
Favna
Favna14mo ago
also I see a bunch of console.log only, no styles or anything I said "like the plugin" so look at the plugin's code 👀
Sayed
SayedOP14mo ago
That's a temp form Shit the source is too large Is there any easier way?
Favna
Favna14mo ago
wdym too large. It's just like 3 files or something lol
Sayed
SayedOP14mo ago
Can I implement it or something like this? Is there any way to register my customLogger that extends ILogger
Favna
Favna14mo ago
I just told you how
Sayed
SayedOP14mo ago
How? 👀
Favna
Favna14mo ago
look at the plugin's code, it has the answer im not here to spoon feed you code
Sayed
SayedOP14mo ago
SapphireClient.plugins.registerPreGenericsInitializationHook(LoggerPlugin[preGenericsInitialization], 'Logger-PreGenericsInitialization');
SapphireClient.plugins.registerPreGenericsInitializationHook(LoggerPlugin[preGenericsInitialization], 'Logger-PreGenericsInitialization');
?
Favna
Favna14mo ago
that's part of it yes
Sayed
SayedOP14mo ago
Should I copy all of this?
No description
Sayed
SayedOP14mo ago
pepeHmmCoffee
Favna
Favna14mo ago
you can follow a different structure and you can merge some files if you want but yes and you dont need the register if you just inline it to your client you'll see how the plugin modifies the client options, you can just inline that
Sayed
SayedOP14mo ago
Ok but where to type this line SapphireClient.plugins.registerPreGenericsInitializationHook(LoggerPlugin[preGenericsInitialization], 'Logger-PreGenericsInitialization'); before client instance of after
Favna
Favna14mo ago
before just like how plugins are called before FWIW the reason I (and anyone else ) wont spoonfeed all the answers and code is because at that point we may as well be writing your bot for you (which would cost you anyway). We expect at least some proactiveness and self incentive from developers. Questions like the ones you've been asking you could've found the answers to very easily by just trying and if it doesn't work try something else and again and again, that's a far far far better way to learn than gettting all the answers on a silver plater.
Sayed
SayedOP14mo ago
First off, thanks for your help and patience. I'm new to this framework, and despite extensive research, I'm struggling to find the answers I need. I'm genuinely committed to gaining more experience with this framework through docs, but sometimes my inquiries are kept without clear answers. Seeking guidance from experienced individuals is much better.
Daniel Passos
Daniel Passos14mo ago
I feel your pain. I spend hours trying to replace the default Logger provided by the plugin using the ClientOptions:
logger: {
instance: new MyLogger()
},
logger: {
instance: new MyLogger()
},
Until I realized that is not possible because the plugin always create a new instance ignoring what we pass on ClientOptions:
public static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void {
options.logger ??= {};
options.logger.instance = new Logger(options.logger);
}
public static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void {
options.logger ??= {};
options.logger.instance = new Logger(options.logger);
}
I opened an issues and will send a PR for it: https://github.com/sapphiredev/plugins/issues/496
Favna
Favna14mo ago
Also said on the GH issue but if you want to use your own instance just dont use the plugin... Issue closed as "wont fix"
Want results from more Discord servers?
Add your server