118

I installed forever and am using it, finding it quite funny.

But I realized that the logs are placed to somewhere else. Is there any tips?

bryanmac
  • 38,941
  • 11
  • 91
  • 99
AGamePlayer
  • 7,404
  • 19
  • 62
  • 119
  • if you just want to simply log the console.log result in the terminal directly use forever logs app.js -f This works pretty fine. – Deluar Hossen Jan 03 '23 at 17:25

11 Answers11

150

Forever takes command line options for output:

-l  LOGFILE      Logs the forever output to LOGFILE
-o  OUTFILE      Logs stdout from child script to OUTFILE
-e  ERRFILE      Logs stderr from child script to ERRFILE

For example:

forever start -o out.log -e err.log my-script.js

See here for more info

bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • 7
    what is the default path if I don't specify any parameters but just use like `forever myapp`? thanks! – AGamePlayer Jan 09 '14 at 15:07
  • 3
    I don't see it documented - I think it changed over time. I see old logs in ~/.forever folder. But I updated very recently and at least on my mac if I don't specify a log file name, it writes console.log to the terminal. – bryanmac Jan 10 '14 at 12:38
  • 1
    -a is also needed as an option if the files already exist. forever -a -o out.log -e err.log my-script.js – swateek Apr 07 '16 at 09:47
  • this gave me the output in the console and stopped the script when I stopped the output. using `forever start` with the same log parameters did what I wanted – Flion Aug 23 '16 at 10:52
  • 2
    What's the difference between LOGFILE and OUTFILE? For me it seems they contain exactly the same information! – Dominic Feb 27 '17 at 13:09
  • @bryanmac I think you forgot to add "action" key in your example forever start -o out.log -e err.log my-script.js – Bikash Mar 24 '17 at 06:45
  • 3
    @Dominic LOGFILE includes **all** output including output from the forever process, OUTFILE only includes stdout from your child script. – Joseph238 Apr 18 '17 at 21:53
  • 1
    Note that the order is important. I accidentally put -o out.log at the end (forever start my-script.js -o out.log), which definitely doesn't work. – wottle Dec 07 '19 at 15:17
88

Forever, by default, will put logs into a random file in ~/.forever/ folder.

You should run forever list to see the running processes and their corresponding log file.

Sample output

>>> forever list
info:    Forever processes running
data:        uid  command       script forever pid  logfile                         uptime
data:    [0] 6n71 /usr/bin/node app.js 2233    2239 /home/vagrant/.forever/6n71.log 0:0:0:1.590

However, it's probably best to specify with -l as mentioned by bryanmac.

Liyan Chang
  • 7,721
  • 3
  • 39
  • 59
  • 1
    Its not always a random file. If you specified a uid with the --uid flag when starting then it will create a log file using the specified uid. – ddelrio1986 Mar 05 '15 at 16:41
23

if you run the command "forever logs", you can see where are the logs files.

Source: https://github.com/foreverjs/forever

JosMarRivera
  • 523
  • 4
  • 13
13

try the command

> forever logs

or

> sudo forever logs

you will get the log file's location

Community
  • 1
  • 1
Moh .S
  • 1,920
  • 19
  • 19
8

It is a old question but i ran across the same issues. If you wanna see live output you can run

forever logs

This would show the path of the logs file as well as the number of the script. You can then use

forever logs 0 -f

0 should be replaced by the number of the script you wanna see the output for.

Untimely Answers
  • 512
  • 1
  • 6
  • 18
5

This worked for me :

forever -a -o out.log -e err.log app.js
Lafexlos
  • 7,618
  • 5
  • 38
  • 53
Zubair
  • 65
  • 1
  • 7
5

Need to do normal forever start script.js to start, and to check console/error logs use forever logs this will print list of all logs being stored by forever and then you can use tail -f /path/to/logs/file.log and this will print live logs to your window. hit ctrl+z to stop logs print.

BanwariLal Bamalwa
  • 439
  • 1
  • 4
  • 8
2

By default forever places all of the files it needs into /$HOME/.forever. If you would like to change that location just set the FOREVER_ROOT environment variable when you are running forever:

FOREVER_ROOT=/etc/forever forever start index.js
Loup G
  • 169
  • 1
  • 11
1

Help is your best saviour, there is a logs action that you can call to check logs for all running processes.

forever --help

Shows the commands

logs                Lists log files for all forever processes
logs <script|index> Tails the logs for <script|index>

Sample output of the above command, for three processes running. console.log output's are stored in these logs.

info:    Logs for running Forever processes
data:        script    logfile
data:    [0] server.js /root/.forever/79ao.log
data:    [1] server.js /root/.forever/ZcOk.log
data:    [2] server.js /root/.forever/L30K.log
bhupen.chn
  • 73
  • 5
1

Based on bryanmac's answer. I'm just saving all logs into one file and then reading it with tail. Simple, but effective way to do this.

forever -o common.log -e common.log index.js && tail -f common.log

Niko9911
  • 361
  • 1
  • 6
  • 13
0

You need to add the log destination specifiers before the filename to run. So

forever -e /path/error.txt -o /path/output.txt start index.js

user450821
  • 51
  • 1
  • 2