Hello Everyone,
Well I’m working on a small project with very simple queries i had to log my errors in case they cause problems on respond side. I used winston module to do this here the way it works.
First start requiring it 🙂
var winston = require(“winston”);
Then i created custom transporter, normal way it was sending info to console, i wanted to keep these information in a file called error.log like usual apache
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({filename:’error.log’})
]
});
i was inserting some datas to mysql using SET command.
lets say
var post = {GAME:gameName}
and my query
connection.query(“INSERT INTO crazyboy.POSTS SET ?”, [post], function(err,result){logger.log(‘info’, err)})
at the end of query i called a function in case i got some error, inside the function i have my custom logger i could use winston.log too but as i said i needed a file. its output would look like info: mysql error info
Next thing i will add time in that log file but for now its working