Add logger to an existing chat app

106 Views Asked by At

I'd like to log usernames/dates of people coming in and out a let's chat server instance. I was told bunyan and winston are good candidates but I have no clue on how to implement them on this specific project.

I'm not sure on which file I have to instantiate them and how to catch username when login and when logout. My bet is in controllers/account.js but it's clearly out of my knowledge.

As a result I'd really like to obtain a rotated file with :

20171104-15:10:14 - LOGIN username with IP x
[...]
20171104-19:23:15 - LOGOUT username
1

There are 1 best solutions below

0
On

Got something I'm happy with :

  1. added console.log('LOGIN', d); and console.log('LOGOUT', d); in room.js
  2. use pm2 and pm2-logrotate module to start my app, store logs end rotate them

Thanks to @VtoCorleone for his indications

Since there are certainly better ways to achieve this, I welcome other ideas.