简体   繁体   中英

How to get logs of NodeJs application running in forever npm?

I was wondering, is there any way I can check out the logs of the my nodejs server when I've forever'd it using forever start server.js to look at what's being logged, check any live errors and such.

I looked at their documentation but couldn't find anything related to this. I want to be able to look at the console.

First find out where your logs are stored using:

sudo forever list

for each process you can see something like this as logfile:

/root/.forever/_Jht.log

use 'tail -f' to monitor its changes:

sudo tail -f /root/.forever/_Jht.log

You can also set your desired path for log files, see this:

https://stackoverflow.com/a/21021251/1119611

As forever start an application on background it gets hard to access old logs. If you can use a library for maintaining logs, I will suggest simple-node-logger . Using this library you can save all your logs on a file and can access that file any time using:

tail -f logsFile.txt

Using this command this will keep printing new changes over logsFile.txt as logger keep updating logs. This will help you to maintain all the logs for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM