NodeJS console log buffer - how to clear - node.js

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.

Related

Angular 9 SSR logs - avoid having the whole body of the main.js in our logs

Since we changed our project to Server-Side Rendering we have a huge amount of logs coming from our client. The main problem is that every log entry has the body of the main.js in it. So about 80.000 chars in every log entry. Our logs are raising up to 30GB every day because of that.
we want to avoid logging the main.js into our logs.
What we have tried so far:
override for console.log with empty function in production when we are on the server-side (isServer etc.).
a hook for stdout and stderr on the node server to catch all outgoing logs and cut the main.js out. but even that didn´t work.
I think it should be kind of a configuration issue. I could not find out if Angular 9 or Angular Universal has some kind of log level settings. Any suggestions?

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

node-watch does not watch directory when the app runs via forever.js

I have an app that monitors a directory for file changes and the send a notification via socket.io to the user. and this works great when i run node app.js but when i start it with forever start /dir/to/app.js the application runs and you can connect to it from the browser but no notification from node-watch are received. No errors that im aware of show up.
You probably have "watch": true in your forever config file.
That will cause your whole app to restart whenever there is a file change, which will cause node-watch to be restarted with the current state of the filesystem, so node-watch will never be able to detect a change.
If your socket pool is stored outside the node process' memory (EG. using the socket.io-redis adapater), your browser client will automatically reconnect after the app restarts without any issues.

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

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?

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