Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
You can write your own logger, which is essentially a wrapper over an entry in a file, which can then be imported anywhere, or you can use ready-made libraries with many settings, for example:
Winston
It may also be useful to read about log rotation, Winston has an extension for this :
winstion-log-rotation
There is a much simpler and more efficient way. In case of an error or execution of any command at the end, you can write this code:
const fs = require('fs');
var currentdate = new Date();
var datetime = "Время: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " | "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
let info = `Канал: ${message.channel.id} - ${message.author.tag} забанил ${puser.user.tag} навечно, по причине ${reason}.`
fs.appendFileSync("logs.txt","\n"+`${datetime}`+` ${info}`);
info
. The file to be written must be specified; each event will be entered from a new line! The same can be done with error output! I hope you find it useful :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question