Can I log socket.io debug information to a file? - node.js

I'm running node.js with socket.io and I'd like to log the debug information (the information that shows in the node.js console when you run socket.io with default options) to a file, is there any way to do this?

Related

How to access a Node.js application log lauched through pm2

I've been developing a Node.js application using Socket.IO, Express, MySql and https and everything worked fine until I "deamonized" it with pm2. Now, my socket seems somehow unresponsive and I'd like to debug it. The problem is that I can't seem to find where the console.log() function from this code outputs its text anymore.
I case you'd like to know, all my pm2 processes are online and I can refresh my pages from the client side. But there should be a fonction on the server that triggers an event on the client side when something happens in the database and it does not.
Could tell me where the output from consone.log() is goes?
You can access the logs with the pm2 logs command
http://pm2.keymetrics.io/docs/usage/log-management/
the problem is that while your server is running and you use
pm2 log
all logs will be displayed except
console.log()
all you have to do is instead of pm2 log, run
pm2 logs
note the "s" at the logs. hope this helps
From PM2 docs:
PM2 allows you to easily manage your application’s logs. You can
display the logs coming from all your applications in real-time, flush
them, and reload them. There are also different ways to configure how
PM2 will handle your logs (separated in different files, merged, with
timestamp…) without modifying anything in your code.
http://pm2.keymetrics.io/docs/usage/log-management/
And other SO question:
Make pm2 log to console

NodeJS console log buffer - how to clear

I'm running nodejs (using nodemon) and outputting a ton of stuff to the console for debug.
But when the app is stopped and restarted, the entire historical console log output is re-displayed. How do I clear that?
Doing something like this in the app:
console.log('\x1Bc');
...will clear the current console screen but not the buffered log which re-appears when the app is restarted.

Logging NodeJS application in production

I am a beginner to Node. Would anyone tell how to handle errors in NodeJS? Also how to define node server to write its logs to a default file instead writing to console.
Winston is a good npm package for logging data to files or to a database (Mongo).

How do I find out where my Express app the response is being sent/finished?

I'm getting Error: Can't set headers after they are sent in my app. I know a response is being sent before the response I intend to deliver, but I'm not sure where that's coming from. Can I log to the console when a respnose has been sent? I'm currently using morgan for logging, but it only seems to log requests. I can't find a way to log every response as well.
If not, what is another effective way to hunt this problem down?
Update: This app runs on Azure and uses the Azure SDK for node or else I would try running it through the node debugger or node-inspector. I don't think there's a way to do this while also running the app in the emulator. I could be wrong about that.
Your error says that there was a response send already, check your code with the node-inspector or any other debugging tool and search for the spot.
Here the node-inspector.
And since you work with Azure this should help you getting started with the node-inspector.

Socket.io - Easiest way to log values from the server

When you are testing your javascript on the server (server.js) file using socket.io, you can't use console.log(), or alert().
What is the easiest way to log or alert a value for testing purposes?
Of course you can use console.log
It just gets logged to the terminal.
Node Docs on console
I log to syslog via the node-syslog package that way I can still see the logs even when the server is running in the background.

Resources