How to detect memory leak in project?
Depends on what the issue is, the best would be to debug by using console.log.
Which variable need I log for debug?
Well, that depends a lot. The best ways to detect a memory issue is just really using a logger that logs everything you do, for example:
myLogger.debug("script is starting")
myLogger.debug("Adding a message hook.");
bot.on("message", async msg => {
myLogger.debug("Received message from %s", msg.author.tag);
// do stuff with message.
myLogger.debug("Handled message from %s", msg.author.tag);
});
I can recommend my own logging library:
sorry, but I don’t understand this module ;/
What is it that you don’t understand? I can try and help you.
Anyway, there are a two terms you should now:
Transport is an object that sends the message to some destination, for example the console or a file.
Logger is an object that takes a message and sends it to its transports.
And the way it works is;
- You create a logger:
const myLogger = new Logger()
- You create transport(s):
const myConsoleTransport = new LogConsoleTransport(data => Logger.getLevelName(data.level) + " " + data.message)
. - You add the transport to the logger:
myLogger.addTransport(myConsoleTransport)
- You start logging stuff:
myLogger.debug("Hello World")
1 Like