Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I combine the output and error logs? #337

Closed
dandv opened this issue Mar 7, 2014 · 8 comments
Closed

How can I combine the output and error logs? #337

dandv opened this issue Mar 7, 2014 · 8 comments

Comments

@dandv
Copy link
Contributor

dandv commented Mar 7, 2014

forever has a -l option that directs both STDOUT and STDERR of the app into the same file. This is useful as I can see after which operations (output via console.log) some error has occurred (output via console.error).

How can I do this with pm2?

@soyuka
Copy link
Collaborator

soyuka commented Mar 7, 2014

I don't think it's a good idea but perhaps that setting the same output file into a JSON declaration would work ;).

@dandv
Copy link
Contributor Author

dandv commented Mar 7, 2014

I tried passing the same output file to -o and -e, but pm2 logs was confused by that. Every STDOUT line was shown both as "out" and as "err".

@Unitech Unitech mentioned this issue Apr 4, 2014
10 tasks
@Unitech
Copy link
Owner

Unitech commented Apr 14, 2014

You can now merge all logs of the same process name to the same output and error file via the option --merge-logs

@Unitech Unitech closed this as completed Apr 14, 2014
@dandv
Copy link
Contributor Author

dandv commented Apr 15, 2014

Let's say I only have one process. Can --merge-logs interleave the -e (error) and -o (output) logs into one file? This would assist in seeing what has happened before an error occurred, because the error message itself in a separate file will be out of context.

@dandv
Copy link
Contributor Author

dandv commented Apr 17, 2014

Could we maybe reopen this issue? As I see, --merge-logs combines logs from instanced, but not STDOUT and STDERR.

Here's a workaround I found, until pm2 enables support for this. It's a bit more complicated because of the numbers added to the end of the log filenames.

  MYLOG_BASENAME="myapp.log"
  pm2 start myapp.js -o $MYLOG_BASENAME.out -e $MYLOG_BASENAME.err
  ACTUAL_LOG=$(pm2 -m l | grep -o /.\*$MYLOG_BASENAME.\*out)
  ACTUAL_ERR=$(pm2 -m l | grep -o /.\*$MYLOG_BASENAME.\*err)
  tail -f $ACTUAL_LOG $ACTUAL_ERR | tee -a $MYLOG_BASENAME.both

Please let me know if there's a simpler way to achieve this.

@dandv
Copy link
Contributor Author

dandv commented May 29, 2014

Any updates? The workaround above require running tail all the time, in parallel with the app. Cumbersome.

@liukun
Copy link

liukun commented Mar 3, 2016

Seems no good options here. My best bet is to use Heka or Logstash listening on TCP to manage logs yourself.

@soyuka
Copy link
Collaborator

soyuka commented Mar 4, 2016

#1996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants